Get user location on tap/longpress on the screen mapforge API - java

I would like to get user location when I tap/longpress on the screen using the mapforge API...
this code is not fired even if I longpressed on the screen.
mapView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
toastLong("onlongclick");
return false;
}
});

With Little Modify
mapView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Long Clicked is working ", Toast.LENGTH_SHORT).show();
return true;
}
});

Related

how to show image when writing on the text

I want to show an image when the user writing on EditText,
here the same output when touching the EditText :
menuH.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
menuH2.setVisibility(VISIBLE);
return true;
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
menuH2.setVisibility(View.INVISIBLE);
Intent intent = new Intent(getApplicationContext(), Index.class);
startActivity(intent);
}
return true;
}
});
So, I need the function that do the same output but when the user writing on the EditText,, Thanks on advanced :)
Explanation :
look at the picture:
when the user write sth on the edit text i want to show an image, if we assume (abbruch and ok) are images so i want to show them when writing, but when the user stop writing on the EditText and switch to another edit text the image disappear
Try the TextChangedListener, like :
menuH.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Show your image
}
});

How to prevent method to be called twice?

I want to check programmatically whether the function is called or not. If it is called before, then do not allow and ignore to be called for the second time, if not then let button to call. Why i need to do this is because of i have a longClick button to run certain functionality, if user forgot to do this then however user will click another button which i will place the same functionality. I need to prevent running same function for twice.
public class ActivityA extends Activity{
private static boolean isScreenShotTaken = false;
blankcard.setOnLongClickListener(new OnLongClickListener() {
if(!isScreenShotTaken)
{
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
isScreenShotTaken = true;
}
return false;
}
});
btnsend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Templates.this, MailCard.class);
intent.putExtra("name", Name);
if(!isScreenShotTaken)
{
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
isScreenShotTaken = true;
}
startActivity(intent);
}
});
public Bitmap takeScreenshot() {
// code exist here
//if called once, second call ignore
}
public void saveBitmap(Bitmap bitmap) {
// code exist here
//if called once, second call ignore
}
}
Thank you for suggestions.
My version:
I'd write it so:
// In the declaration section of your class.
private static boolean isScreenShotTaken = false;
// In the code.
btnsend.setOnClickListener
(
new View.OnClickListener()
{
#Override
public void onClick(View v)
{
if(!isScreenShotTaken)
{
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
isScreenShotTaken = true;
}
}
}
);
blankcard.setOnLongClickListener
(
new OnLongClickListener()
{
#Override
public boolean onLongClick(View arg0)
{
if(!isScreenShotTaken)
{
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
isScreenShotTaken = true;
}
}
}
);
simple:
public Bitmap takeScreenshot() {
// before start
blankcard.setEnabled(false);
btnsend.setEnabled(false);
// do your sutff
... here ...
// at the end
blankcard.setEnabled(true);
btnsend.setEnabled(true);
}
if you're using an AsyncTask or similar, put those calls in preExecute and postExecute
If you have a button
once the button is pressed on .. In onclickListener
button.setclickable(false);
then button can't be pressed .
and if you have some method. than take a gloabal boolean variable
boolean isFirstTime= false;
and once you get into the method set it to true;
isFirstTime= true;
Why dont you use a global flag variable??
something like,
btnsend.setOnClickListener(new View.OnClickListener() {
#Override
if(flag == true)
{
public void onClick(View v) {
// TODO Auto-generated method stub
// Bitmap bitmap = takeScreenshot();
// saveBitmap(bitmap);
flag = 1;
}
}
});
So even though setOnClickListener is called, it wont execute the code within.

Android App StartApp Ads Error

I made a game and used an ads company on it (StartApp). I wanna use Interstitial Ads on it. I followed the step they show but can't achieve it. I'm getting error. Here is the LogCat:
http://i.stack.imgur.com/SaIXE.png
Here is the codes:
GameActivity.java
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException
{
StartAppAd.init(this, "10254544", "20454573");
}
MenuScene.java
private StartAppAd startAppAd = new StartAppAd(activity);
#Override
public void createScene() {
startAppAd.showAd();
startAppAd.loadAd();
}
Check the Manifest.xml file. Be sure you wrote the right package name in there.
Try This code and u should update manifest file also
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StartAppSearch.showSearchBox(this);
StartAppAd.init(this, "107181003", "211487617");
StartAppSearch.init(this, "107181003", "211487617");
btnnext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startAppAd.showAd(); // show the ad
startAppAd.loadAd(); //load next add
Intent intent=new Intent(getApplicationContext(),Second.class);
startActivity(intent);
}
});
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
boolean _active = true;
}
return true;
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
startAppAd.onPause();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
startAppAd.onResume();
}
#Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
private StartAppAd startAppAd = new StartAppAd(this);
#Override
public void onBackPressed() {
startAppAd.onBackPressed();
super.onBackPressed();
}
and update in manifest file also
You can not use the
startAppAd.showAd();
startAppAd.loadAd();
inside the Scene class (MenuScene). Instead you can try below method.
In GameActivity class you must be having KeyEvent method. put the code to show the startApp ads in there as below,
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if(SceneManager.getInstance().getCurrentSceneType().toString() == "SCENE_MENU"){
try{
startAppAd.showAd(); // show the ad
startAppAd.loadAd(); // load the next ad
}catch(Exception e){
}
}
try{
SceneManager.getInstance().getCurrentScene().onBackKeyPressed();
}catch(Exception e){
}
}
return false;
}
Regards,
Deepak

Get function value in Android

Question: I am trying to take the index of the selected radio button and use that in the onClick function.
Example:
btnCalc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (getIndex(k) == 0) {
DO THIS
}
if (getIndex(k) == 1) {
DO THAT
}
});
I have the following code in my Android app:
int POS; //global variable assigned right under MainActivity
final RadioGroup rgTypeOfTrip = (RadioGroup) findViewById(R.id.rgTripType);
Button btnCalc = (Button) findViewById(R.id.btnCalculate);
btnCalc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, Integer.toString(getIndex(POS1)), Toast.LENGTH_SHORT).show(); //DOESN'T WORK
});
rgTypeOfTrip.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
// Method 1
int pos=rgTypeOfTrip.indexOfChild(findViewById(checkedId));
getIndex(pos);
Toast.makeText(MainActivity.this, String.valueOf(pos), Toast.LENGTH_SHORT).show();
}
});
public int getIndex(int POS1) {
Toast.makeText(MainActivity.this, Integer.toString(POS1), Toast.LENGTH_SHORT).show(); // WORKS
return POS1;
}
How can I achieve this line:
Toast.makeText(MainActivity.this, CALL FUNCTION GETINDEX() to get value, Toast.LENGTH_SHORT).show();
To call the function to get the value of k?
Assuming your question is in the Toast such that it is: "CALL FUNCTION GETINDEX() to get value"
Toast.makeText(MainActivity.this, Integer.toString(getIndex(int)), Toast.LENGTH_SHORT).show();
You pass in the integer that is returned though so you could just go with the following (under my assumptions of your code):
Toast.makeText(MainActivity.this, Integer.toString(int), Toast.LENGTH_S

Webview shows white blank page in Ice Cream Sandwitch

In my webview I have loaded a URL which have an embeded video player of a tv channel live stream. It is working correctly in all the OS version of Android except ICS(4). First time It plays the video well, but when I go back and come again in that page containing the video then the video doesnt loads and shows a blank white page. If I force stop the app from the application setting and start the app again then It runs well then appears white screen again as usual, I have implemented a lot of tactics and this is the latest , I am totally stuck here:
public class Livetvwebview extends Activity {
RelativeLayout a;
WebView webtv;
String url;
VideoView video;
WChromeClient chromeClient;
WebViewClient wvClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.livewebview);
Toast.makeText(getApplicationContext(),
"Channel is loading..This may take upto a minute",
Toast.LENGTH_LONG).show();
url = getIntent().getStringExtra("tvchannel");
Log.i("TVURL", url);
webtv = (WebView) findViewById(R.id.webViewlive);
webtv.clearCache(true);
webtv.loadUrl(url);
webtv.getSettings().setLoadWithOverviewMode(true);
webtv.getSettings().setUseWideViewPort(true);
webtv.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webtv.setWebChromeClient(new WChromeClient());
webtv.setWebViewClient(new myWebClient());
webtv.getSettings().setJavaScriptEnabled(true);
webtv.getSettings().setPluginState(PluginState.ON);
webtv.getSettings().setDomStorageEnabled(true);
}
public class myWebClient extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
}
#SuppressLint("NewApi")
#Override
protected void onPause() {
// TODO Auto-generated method stub
WebSettings webSettings = webtv.getSettings();
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webtv.onPause();
this.finish();
super.onPause();
}
#SuppressLint("NewApi")
#Override
protected void onResume() {
webtv.onResume();
super.onResume();
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
// android.os.Process.killProcess(android.os.Process.myPid());
Editor editor = getSharedPreferences("clear_cache",
Context.MODE_PRIVATE).edit();
editor.clear();
editor.commit();
trimCache(this);
super.onDestroy();
}
class WChromeClient extends WebChromeClient {
#Override
public void onProgressChanged(WebView view, int progress) {
Log.i("Method", "Onrogresschanged");
Livetvwebview.this.setTitle("Loading...");
Livetvwebview.this.setProgress(progress * 100);
if (progress == 100)
Livetvwebview.this.setTitle("LiveTv");
}
#Override
public void onShowCustomView(View view, CustomViewCallback callback) {
// TODO Auto-generated method stub
super.onShowCustomView(view, callback);
if (view instanceof FrameLayout) {
FrameLayout frame = (FrameLayout) view;
if (frame.getFocusedChild() instanceof VideoView) {
webtv.setVisibility(View.GONE);
video = (VideoView) frame.getFocusedChild();
FrameLayout.LayoutParams par = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
par.gravity = Gravity.CENTER_HORIZONTAL;
video.setLayoutParams(par);
frame.removeView(video);
a.addView(video);
video.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
Toast.makeText(Livetvwebview.this,
"Video completed", Toast.LENGTH_LONG)
.show();
}
});
video.setOnErrorListener(new OnErrorListener() {
#Override
public boolean onError(MediaPlayer mp, int what,
int extra) {
Toast.makeText(Livetvwebview.this,
"Encountered some error", Toast.LENGTH_LONG)
.show();
return true;
}
});
video.start();
}
}
}
}
public static void trimCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
} catch (Exception e) {
// TODO: handle exception
}
}
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}
}
Can anyone help me please?
After researching for a long long time I myself figured out that when I write in the onPause()
webtv.destroy();
instead of
webtv.onPause();
solves the problem :)

Categories