Android seekbar progress not update - android

I am using seekBar for soundpool volume control on my app, I use PopupWindow for seekbar and everything works fine except, whenever I change or pause my activity, and I open seekbar popupwindow again, the seekbar is no longer the value I last had saved. But it always returns to its default value 100%, even I use SharedPreferences what works well, but only if I do not leave current activity.
public class ActivityMain extends Activity implements OnTouchListener, OnMenuItemClickListener {
SoundManager snd;
OnSeekBarChangeListener barChange1;
private int soundID;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main_activity);
}
public void onRestart() {
super.onRestart();
}
public void onResume() {
super.onResume();
final Button btnOpenPopup = (Button)findViewById(R.id.button6);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
barChange1 = new OnSeekBarChangeListener()
{
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
SharedPreferences prefs = getBaseContext().getSharedPreferences("mySharedPrefsFilename1", Context.MODE_PRIVATE);
prefs.edit().putInt("seekBarValue", seekBar.getProgress()).commit();
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) { }
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
snd.setVolume((float)progress/100.0f);
}
};
SeekBar volbar1 = (SeekBar)popupView.findViewById(R.id.VolBar1);
volbar1.setMax(100);
int value = 0;
SharedPreferences prefs = getBaseContext().getSharedPreferences("mySharedPrefsFilename1", Context.MODE_PRIVATE);
value = prefs.getInt("seekBarValue", 100);
volbar1.setProgress(value);
volbar1.setOnSeekBarChangeListener(barChange1);
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 60, 20);
}});
{
}
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
snd = new SoundManager(getApplicationContext());
soundID = snd.load(R.raw.sound_1);
ImageView img01 = (ImageView) findViewById(R.id.imageView11);
img01.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
}
snd.play(soundID);
return false;
}
});
}
#Override
public boolean onMenuItemClick(MenuItem item) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
#Override
protected void onPause() {
super.onPause();
snd.unloadAll();
}
}

Put this onResume()
int value = 0;
SharedPreferences prefs = getBaseContext().getSharedPreferences("mySharedPrefsFilename1", Context.MODE_PRIVATE);
value = prefs.getInt("seekBarValue", 100)
volbar1.setProgress(value);

I am doing the same thing. Its working for me. Here is my code. It does not have all the Sound stuff.
package com.titlesource.testproject;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.SeekBar;
public class ActivityMain extends AppCompatActivity {
SeekBar.OnSeekBarChangeListener barChange1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_main);
}
public void onRestart() {
super.onRestart();
}
public void onResume() {
super.onResume();
final Button btnOpenPopup = (Button)findViewById(R.id.button6);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LinearLayoutCompat.LayoutParams.WRAP_CONTENT, LinearLayoutCompat.LayoutParams.WRAP_CONTENT);
barChange1 = new SeekBar.OnSeekBarChangeListener()
{
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
SharedPreferences prefs = getBaseContext().getSharedPreferences("mySharedPrefsFilename1", Context.MODE_PRIVATE);
prefs.edit().putInt("seekBarValue", seekBar.getProgress()).commit();
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) { }
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
};
SeekBar volbar1 = (SeekBar)popupView.findViewById(R.id.VolBar1);
volbar1.setMax(100);
int value = 0;
SharedPreferences prefs = getBaseContext().getSharedPreferences("mySharedPrefsFilename1", Context.MODE_PRIVATE);
value = prefs.getInt("seekBarValue", 100);
volbar1.setProgress(value);
volbar1.setOnSeekBarChangeListener(barChange1);
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 60, 20);
}});
{
}
}
}

Related

Unity and Android Studio integration hardware not supported

I have attempted to integrate simple Unity shape figure to display using Android Studio IDE however it shows like this:
Your hardware does not support this application sorry
My phone is Android 6.0 Marshmallow and the version of Unity is 5.4.1f1
The logcat in Android Studio does not show any error except when I dismiss the message about hardware not supported, then crashed.
package com.cs4.android_lcitresearch.schoolsafetyemergencyapplication.maps_class;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;
import com.cs4.android_lcitresearch.schoolsafetyemergencyapplication.R;
import com.cs4.android_lcitresearch.schoolsafetyemergencyapplication.SplashInterface;
import com.cs4.android_lcitresearch.schoolsafetyemergencyapplication.comic_class.comiclass;
import com.cs4.android_lcitresearch.schoolsafetyemergencyapplication.phone_class.phoneclass;
import com.cs4.android_lcitresearch.schoolsafetyemergencyapplication.scenario_class.scenarioclass;
import com.unity3d.player.UnityPlayer;
public class lcoldclass extends AppCompatActivity {
protected UnityPlayer mUnityPlayer;
public static Context mContext;
private Handler handler=new Handler();
public FrameLayout fl_forUnity;
public ImageButton scenario1, comic1, phoneclass1, maps1, homeb;
public Toolbar toolbar;
public TextView txttitle;
public void init_home() {
homeb= (ImageButton)findViewById(R.id.homebutton);
homeb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent first = new Intent(lcoldclass.this,SplashInterface.class);
startActivity(first);
}
});
}
public void init_scenario() {
scenario1= (ImageButton)findViewById(R.id.scenario);
scenario1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent first = new Intent(lcoldclass.this,scenarioclass.class);
startActivity(first);
}
});
}
public void init_comic() {
comic1= (ImageButton)findViewById(R.id.comicbutton);
comic1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent first = new Intent(lcoldclass.this,comiclass.class);
startActivity(first);
}
});
}
public void init_phone() {
phoneclass1= (ImageButton)findViewById(R.id.callbutton);
phoneclass1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent first = new Intent(lcoldclass.this,phoneclass.class);
startActivity(first);
}
});
}
public void init_maps() {
maps1= (ImageButton)findViewById(R.id.mapsl);
maps1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent first = new Intent(lcoldclass.this,SecondInterfaceF.class);
startActivity(first);
}
});
}
private void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.include2);
toolbar.showOverflowMenu();
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
mContext = this;
getWindow().takeSurface(null);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFormat(PixelFormat.RGB_888);
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
mUnityPlayer.init(glesMode, trueColor8888);
View playerView = mUnityPlayer.getView();
setContentView(R.layout.lcmapsold1);
this.fl_forUnity = (FrameLayout)findViewById(R.id.frameunity);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(750, 630);
fl_forUnity.addView(playerView, 0, lp);
initToolbar();
init_home();
init_scenario();
init_comic();
init_phone();
init_maps();
txtformation_init();
mUnityPlayer.requestFocus();
}
///////////////////////////// Unity Codes Override///////////////////////////////////////////
// Quit Unity
#Override protected void onDestroy ()
{
mUnityPlayer.quit();
super.onDestroy();
}
// Pause Unity
#Override protected void onPause()
{
super.onPause();
mUnityPlayer.pause();
}
// Resume Unity
#Override protected void onResume()
{
super.onResume();
mUnityPlayer.resume();
}
// This ensures the layout will be correct.
#Override public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
// Notify Unity of the focus change.
#Override public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
// For some reason the multiple keyevent type is not supported by the ndk.
// Force event injection by overriding dispatchKeyEvent().
#Override public boolean dispatchKeyEvent(KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
return mUnityPlayer.injectEvent(event);
return super.dispatchKeyEvent(event);
}
// Pass any events not handled by (unfocused) views straight to UnityPlayer
#Override public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); }
#Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); }
#Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
/*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
///////////////////////////// Unity Codes Override///////////////////////////////////////////
}
How to solve it? I cannot understand how users manage to work the program without issues on integration.

Android Application and Observable

i'm developing a simple application on android studio. I'm using "application", "observable", and many more. i got some error like this:
java.lang.RuntimeException: Unable to start activity ComponentInfo{id.wdharmana.doahindu/id.wdharmana.doahindu.MainActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to id.wdharmana.doahindu.app.DoaApplication
2nd error
Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to id.wdharmana.doahindu.app.DoaApplication
3rd error
at id.wdharmana.doahindu.MainActivity.onCreate(MainActivity.java:52)
This is my full MainActivity.java:
package id.wdharmana.doahindu;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.SearchManager;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import id.wdharmana.doahindu.adapter.ListJudulAdapter;
import id.wdharmana.doahindu.app.DoaApplication;
import id.wdharmana.doahindu.data.DefaultData;
import id.wdharmana.doahindu.helper.DoaHelper;
import id.wdharmana.doahindu.model.DoaModel;
import id.wdharmana.doahindu.model.DoaObserver;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
public class MainActivity extends AppCompatActivity implements Observer {
private ListView lvJudul;
private ArrayList<DoaModel> listJudul;
private DoaHelper doaHelper;
public ListJudulAdapter listJudulAdapter;
private DoaApplication application;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvJudul = (ListView)findViewById(R.id.lvListJudul);
listJudul = new ArrayList<DoaModel>();
application = (DoaApplication) getApplication();
application.getDoaObserver().addObserver(this);
doaHelper = new DoaHelper(MainActivity.this);
doaHelper.open();
listJudul = doaHelper.getAllData();
if (listJudul.size()>0) {
bindData();
}else{
insertDefaultData();
}
lvJudul.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
showMeaningDialog(MainActivity.this, listJudul.get(arg2));
}
});
lvJudul.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
deleteDialog(listJudul.get(arg2).getId());
return false;
}
});
}
private void insertDefaultData() {
// TODO Auto-generated method stub
new StoreDefaultData().execute();
}
public void update(Observable observable, Object o) {
if (o.equals(DoaObserver.NEED_TO_REFRESH)){
bindData();
}
}
private class StoreDefaultData extends AsyncTask<Void, Void, Void>{
ProgressDialog mProgressDialog;
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setTitle(getString(R.string.notify_input_data));
mProgressDialog.setMessage(getString(R.string.text_please_wait));
mProgressDialog.show();
}
#Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
for (int i = 0; i < DefaultData.defaultData.length; i++) {
doaHelper.insert(DoaModel.getDoaModel(DefaultData.defaultData[i][0],
DefaultData.defaultData[i][1]));
}
listJudul = doaHelper.getAllData();
return null;
}
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
mProgressDialog.dismiss();
listJudulAdapter = new ListJudulAdapter(MainActivity.this, listJudul);
lvJudul.setAdapter(listJudulAdapter);
}
}
#Override
protected void onDestroy() {
if (doaHelper != null){
doaHelper.close();
}
super.onDestroy();
}
public static void showMeaningDialog(final Activity activity, final DoaModel item) {
final Dialog dialog = new Dialog(activity, R.style.AppCompatAlertDialogStyle);
dialog.setContentView(R.layout.dialog_konten);
dialog.setCancelable(true);
TextView txtKonten = (TextView)dialog.findViewById(R.id.txtMeaning);
TextView txtJudul = (TextView)dialog.findViewById(R.id.txtWord);
Button btnTutup = (Button)dialog.findViewById(R.id.btnTutup);
Button btnEdit = (Button)dialog.findViewById(R.id.btnEdit);
txtKonten.setText(item.getKonten());
txtJudul.setText(item.getJudul());
btnEdit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//FormInputUpdateActivity.toFormInputUpdate(activity, item);
dialog.dismiss();
}
});
btnTutup.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
dialog.show();
}
private void deleteDialog(final int id) {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(MainActivity.this, R.style.AppCompatAlertDialogStyle);
dialog.setTitle("Hapus");
//dialog.setContentView(R.layout.dialog_delete);
dialog.setCancelable(true);
// Button btnYes = (Button)dialog.findViewById(R.id.btnDeleteYes);
// Button btnCancel = (Button)dialog.findViewById(R.id.btnDeleteCancel);
// btnYes.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// // TODO Auto-generated method stub
// doaHelper.delete(id);
// dialog.dismiss();
// Toast.makeText(MainActivity.this, getString(R.string.text_success_delete), Toast.LENGTH_LONG).show();
// application.getDoaObserver().refresh();
// }
// });
//btnCancel.setOnClickListener(new View.OnClickListener() {
// public void onClick(View arg0) {
// TODO Auto-generated method stub
// dialog.dismiss();
// }
//});
dialog.show();
}
public void bindData(){
if (listJudul.size()>0) {
listJudul.clear();
}
listJudul = doaHelper.getAllData();
listJudulAdapter = new ListJudulAdapter(MainActivity.this, listJudul);
lvJudul.setAdapter(listJudulAdapter);
listJudulAdapter.notifyDataSetChanged();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_activity_main, menu);
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true;
}
}
This is DoaApplication.java
package id.wdharmana.doahindu.app;
import android.app.Application;
import id.wdharmana.doahindu.model.DoaObserver;
/**
* Created by WDHARMANA on 9/18/2015.
*/
public class DoaApplication extends Application {
DoaObserver doaObserver;
#Override
public void onCreate() {
super.onCreate();
doaObserver = new DoaObserver();
}
public DoaObserver getDoaObserver(){
return doaObserver;
}
}
No error when build. Please tell me if you have some suggestions. Thanks in advance.
Put DoaApplication in your manifest, in the <application> node as android:name="id.wdharmana.doahindu.app.DoaApplication"
Please make sure your AndroidManifest.xml like that:
<application
android:name="id.wdharmana.doahindu.app.DoaApplication"
... >
...
</application>
I think you forgot to add your

Regarding validation of a paint drawn on a canvas in android

Sir, we are developing an app to teach small children write alphabets.. Here we show a screen with two images where one image is on the right side it is just to show the image of the alphabet, and the the other one is a light image where the user can draw on image for practise. I want to validate the image drawn by the user whether he has drawn correctly on the base image or not.!
(Note: I exactly dont know what is the use of "Scaling" which i used in it.)Can i please get a solution because i tried a lot but cudnt get an answer
The code is:
enter code here
package com.example.androidhive;
import com.example.androidhive.ColorPickerDialog.OnColorSelectedListener;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.support.v4.view.MotionEventCompat;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.Toast;
import android.widget.ViewFlipper;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class FullImgTwoActivity extends Activity implements OnTouchListener {
int pp;
int pickupLinesItemIndex;
int position;
PaintView paintView;
ViewFlipper layout;
int size = 0;
int progress = 0;
ImageView imageView1;
private Bitmap bmp;
private Bitmap operation;
GetScaling scaling;
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
paintView = new PaintView(this);
scaling=new GetScaling(this);
layout = (ViewFlipper) findViewById(R.id.view1);
Intent i = getIntent();
position = i.getExtras().getInt("id");
final ImageAdapterTwo imageAdapterTwo = new ImageAdapterTwo(this);
imageView1 = (ImageView) findViewById(R.id.imageView1);
imageView1.setImageResource(imageAdapterTwo.mThumbIdsx[position]);
bmp=imageView1.getDrawingCache();
layout.setBackgroundResource(imageAdapterTwo.mThumbIdsy[position]);
paintView.setLayoutParams(new LinearLayout.LayoutParams(500, 500));
layout.addView(paintView);
ImageView back = (ImageView) findViewById(R.id.imageView3);
back.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (pickupLinesItemIndex < imageAdapterTwo.mThumbIdsw.length) {
if (position <= 0) {
Toast.makeText(getApplicationContext(), "This is the starting alphabet", 90)
.show();
} else {
imageView1
.setImageResource(imageAdapterTwo.mThumbIdsx[--position]);
layout
.setBackgroundResource(imageAdapterTwo.mThumbIdsy[position]);
}
}
}
});
ImageView nexta = (ImageView) findViewById(R.id.imageView4);
nexta.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (pickupLinesItemIndex > imageAdapterTwo.mThumbIdsw.length) {
//if (position <=imageAdapter.mThumbIds.length) {
Toast.makeText(getApplicationContext(), "This level is done", 90)
.show();
} else {
imageView1
.setImageResource(imageAdapterTwo.mThumbIdsx[++position]);
layout
.setBackgroundResource(imageAdapterTwo.mThumbIdsy[position]);
//}
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.home, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.select_color_menu:
showColorPickerDialogDemo();
break;
case R.id.select_clear_menu:
paintView.clear();
paintView.invalidate();
break;
case R.id.pointers_select_menu:
// pointerDialog();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
private void pointerDialog() {
// TODO Auto-generated method stub
final Dialog d = new Dialog(FullImgTwoActivity.this);
d.setTitle("Increase pointer size");
d.setContentView(R.layout.pointerssize);
SeekBar bar = (SeekBar) d.findViewById(R.id.seekBar1);
Button save = (Button) d.findViewById(R.id.save);
Button cancel = (Button) d.findViewById(R.id.cancel);
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progresValue,
boolean fromUser) {
progress = progresValue;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Display the value in textview
size = seekBar.getMax();
}
});
save.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
paintView.setSize(progress);
d.dismiss();
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
d.dismiss();
}
});
d.show();
}
private void showColorPickerDialogDemo() {
int initialColor = Color.WHITE;
ColorPickerDialog colorpick = new ColorPickerDialog(
FullImgTwoActivity.this, initialColor,
new OnColorSelectedListener() {
#Override
public void onColorSelected(int color) {
paintView.setColo(color);
}
});
colorpick.show();
}
public void Checkimage(View v) {
scaling.checktheimage(imageView1);
scaling.checkpaintimage(paintView);
boolean paint=scaling.bmapaint;
boolean image=scaling.bmapimage;
if(paint!=image){
AlertDialog.Builder al=new AlertDialog.Builder(FullImgTwoActivity.this);
al.setTitle("Please Try Again");
al.setIcon(R.drawable.checkno);
al.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
paintView.clear();
paintView.invalidate();
}
}) ;
al.setNegativeButton("NO",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent in=new Intent(FullImgTwoActivity.this, GridLayoutTwo.class);
startActivity(in);
finish();
}
});
AlertDialog dialog=al.create();
dialog.show();
}else {
AlertDialog.Builder al=new AlertDialog.Builder(FullImgTwoActivity.this);
al.setTitle("Please Go To Next Letter");
al.setIcon(R.drawable.checkno);
al.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent in=new Intent(FullImgTwoActivity.this, GridLayoutTwo.class);
startActivity(in);
finish();
}
}) ;
al.setNegativeButton("NO",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
paintView.clear();
paintView.invalidate();
}
});
AlertDialog dialog=al.create();
dialog.show();
}
}
//#Override
public boolean onCreateOptionsMenu1(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_full_img_two, menu);
return true;
}
#Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
return false;
}
}

Animate weapon ontouch

Hello everyone I would like to implement a method to touch on my image of a ak47, I have written the code but the method does not work on touch as it should. I would like that if you touch the gun that starts the repetition in my code. Thanks in advance
package org.realgunshot;
import android.app.Activity;
import android.app.ActionBar.LayoutParams;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
public class B2 extends Activity {
ImageView bulletshot,bulletempty ;
Boolean click=true;
TextView Display;
Button b1;
int counter = 15 ;
Object mediaPlayerspara,mediaPlayersload;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.b2);
bulletshot=(ImageView)findViewById(R.id.bulletshot);
bulletempty=(ImageView)findViewById(R.id.bulletempty);
b1 = (Button)findViewById(R.id.b1);
Display = (TextView)findViewById(R.id.counter);
final Animation animRotate = AnimationUtils.loadAnimation(this, R.anim.gun);
final Animation animgunshot = AnimationUtils.loadAnimation(this, R.anim.gunshot);
final Animation animbulletempty = AnimationUtils.loadAnimation(this, R.anim.bulletempty);
b1.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
counter --;
Display.setText(""+counter);
if(counter <= 0)
{
counter=1;
mediaPlayerspara = null;
mediaPlayersload = MediaPlayer.create(getBaseContext(),R.raw.sload);
((MediaPlayer) mediaPlayersload).setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayersload) {
// TODO Auto-generated method stub
mediaPlayersload.start();
mediaPlayersload.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mediaPlayersload) {
mediaPlayersload.release();
};
});
}
});
}
else{
bulletshot.setVisibility(View.VISIBLE);
bulletshot.startAnimation(animgunshot);
Handler handlers = new Handler();
handlers.postDelayed(new Runnable() {
public void run() {
bulletshot.setVisibility(View.GONE);
bulletempty.setVisibility(View.GONE);
}
}, 300);
bulletempty.setVisibility(View.VISIBLE);
bulletempty.startAnimation(animbulletempty);
Handler handlers2 = new Handler();
handlers2.postDelayed(new Runnable() {
public void run() {
bulletshot.setVisibility(View.GONE);
bulletempty.setVisibility(View.GONE);
}
}, 2000);
v.startAnimation(animRotate);
final Button button1 = (Button)findViewById(R.id.b1);
button1.setBackgroundResource(R.drawable.ak47_1);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
button1.setBackgroundResource(R.drawable.ak47_0);
}
}, 100);
mediaPlayerspara = MediaPlayer.create(getBaseContext(),R.raw.ak47);
((MediaPlayer) mediaPlayerspara).setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayerspara) {
// TODO Auto-generated method stub
mediaPlayerspara.start();
mediaPlayerspara.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mediaPlayerspara) {
mediaPlayerspara.release();
};
});
}
});}
if(event.getAction() == MotionEvent.ACTION_UP){
return true;
}
return false;
}
});
Button apri = (Button)findViewById(R.id.loadoadd);
apri.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
LayoutInflater layoutInflater= (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.loadoadd, null);
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
popupWindow.setAnimationStyle(R.style.Animation);
Button chiudi1 = (Button)popupView.findViewById(R.id.dismiss);
chiudi1.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
Button load = (Button)popupView.findViewById(R.id.load);
load.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter = 15;
Display.setText(""+counter);
}});
Button add = (Button)popupView.findViewById(R.id.add);
add.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter = 1015;
Display.setText(""+counter);
}});
if (click){
popupWindow.showAtLocation(chiudi1, Gravity.CENTER, 0, 0);
click=false;
}else{
popupWindow.dismiss();
click=true;
}
}});
}
}
I don't think anyone can help you - unless you post your code fully. There are so many things missing...Your OnTouchListener doesn't even check for touch events such as ACTION_DOWN, ACTION_MOVE or anything else.
I would suggest that you take the action when user taps i.e.
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
// Do your firing even
break;
case MotionEvent.ACTION_UP:
//action when user removes finger.
break;
default:
return false;
} // end of switch case
return true;
}
Also, just add a break point in onTouch() and debug to know what is happening and what part is not executing and fix it accordingly.
package org.realgunshot;
import android.app.Activity;
import android.app.ActionBar.LayoutParams;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
public class B2 extends Activity {
ImageView proiettilesparo,proiettilevuoto ;
Boolean click=true;
TextView Display;
Button b1;
int contatore = 15 ;
Object mediaPlayerspara,mediaPlayerscarica;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.b2);
proiettilesparo=(ImageView)findViewById(R.id.proiettilesparo);
proiettilevuoto=(ImageView)findViewById(R.id.proiettilecade);
b1 = (Button)findViewById(R.id.b1);
Display = (TextView)findViewById(R.id.contatore);
final Animation animRotate = AnimationUtils.loadAnimation(this, R.anim.pistola);
final Animation animsparoproiettile = AnimationUtils.loadAnimation(this, R.anim.sparoproiettile);
final Animation animproiettilecade = AnimationUtils.loadAnimation(this, R.anim.proiettilecade);
b1.setOnTouchListener(new OnTouchListener() {
private Handler mHandler;
#Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (mHandler != null) return true;
mHandler = new Handler();
mHandler.postDelayed(mAction, 1);
break;
case MotionEvent.ACTION_UP:
if (mHandler == null) return true;
mHandler.removeCallbacks(mAction);
mHandler = null;
break;
}
return false;
}
Runnable mAction = new Runnable() {
#Override public void run() {
contatore --;
Display.setText(""+contatore);
if(contatore <= 0)
{
contatore=1;
mediaPlayerspara = null;
mediaPlayerscarica = MediaPlayer.create(getBaseContext(),R.raw.scarica);
((MediaPlayer) mediaPlayerscarica).setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayerscarica) {
// TODO Auto-generated method stub
mediaPlayerscarica.start();
mediaPlayerscarica.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mediaPlayerscarica) {
mediaPlayerscarica.release();
};
});
}
});
}
else{
proiettilesparo.setVisibility(View.VISIBLE);
proiettilesparo.startAnimation(animsparoproiettile);
Handler handlers = new Handler();
handlers.postDelayed(new Runnable() {
public void run() {
proiettilesparo.setVisibility(View.GONE);
proiettilevuoto.setVisibility(View.GONE);
}
}, 300);
proiettilevuoto.setVisibility(View.VISIBLE);
proiettilevuoto.startAnimation(animproiettilecade);
Handler handlers2 = new Handler();
handlers2.postDelayed(new Runnable() {
public void run() {
proiettilesparo.setVisibility(View.GONE);
proiettilevuoto.setVisibility(View.GONE);
}
}, 2000);
b1.startAnimation(animRotate);
final Button button1 = (Button)findViewById(R.id.b1);
button1.setBackgroundResource(R.drawable.ak47_1);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
button1.setBackgroundResource(R.drawable.ak47_0);
}
}, 100);
mediaPlayerspara = MediaPlayer.create(getBaseContext(),R.raw.ak47);
((MediaPlayer) mediaPlayerspara).setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayerspara) {
// TODO Auto-generated method stub
mediaPlayerspara.start();
mediaPlayerspara.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mediaPlayerspara) {
mediaPlayerspara.release();
};
});
}
});}
mHandler.postDelayed(this, 100);
}
};
});
Button apri = (Button)findViewById(R.id.caricaoaggiungi);
apri.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
LayoutInflater layoutInflater= (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.caricaoaggiungi, null);
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
popupWindow.setAnimationStyle(R.style.Animation);
Button chiudi1 = (Button)popupView.findViewById(R.id.dismiss);
chiudi1.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
Button carica = (Button)popupView.findViewById(R.id.carica);
carica.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
contatore = 15;
Display.setText(""+contatore);
}});
Button aggiungi = (Button)popupView.findViewById(R.id.aggiungi);
aggiungi.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
contatore = 1015;
Display.setText(""+contatore);
}});
if (click){
popupWindow.showAtLocation(chiudi1, Gravity.CENTER, 0, 0);
click=false;
}else{
popupWindow.dismiss();
click=true;
}
}});
}
I changed it this way, but every time the animation starts from 0, there is a way to continue an action and does not stop and start it again?

Implementing Leadbolt in Android app

I am making my first Android app and I am trying to implement Leadbolt unlocker, I have done everything like Leadbolt documentation, but when I launch app it is always crashing. When I remove implement AdListener from public class FullActivity extends Activity implements AdListener then everything is working. App is crashing when Intent full = new Intent(GridActivity.this, FullActivity.class); and it is not even go to super.onCreate(savedInstanceState); breakpoint.
This is FullActivity.java:
import java.io.IOException;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import com.Leadbolt.AdController;
import com.Leadbolt.AdListener;
public class FullActivity extends Activity implements AdListener{
private AdController myController;
private String MY_LB_SECTION_ID="1111111";
private Integer[] mThumbIds = {
R.drawable.p1,
R.drawable.p2,
R.drawable.p3,
R.drawable.p4,
R.drawable.p5,
R.drawable.p6,
R.drawable.p7,
R.drawable.p8,
R.drawable.p9,
R.drawable.p10,
R.drawable.p11,
R.drawable.p12,
R.drawable.p13,
R.drawable.p14,
R.drawable.p15,
R.drawable.p16,
R.drawable.p17,
R.drawable.p18,
R.drawable.p19,
R.drawable.p20,
R.drawable.p21,
R.drawable.p22,
R.drawable.p23,
R.drawable.p24,
R.drawable.p25,
R.drawable.p26,
R.drawable.p27,
R.drawable.p28,
R.drawable.p29,
R.drawable.p30,
R.drawable.p31,
R.drawable.p32,
R.drawable.p33,
R.drawable.p34,
R.drawable.p35,
R.drawable.p36,
R.drawable.p37,
R.drawable.p38,
R.drawable.p39,
R.drawable.p40,
R.drawable.p41,
R.drawable.p42,
R.drawable.p43,
R.drawable.p44,
R.drawable.p45,
R.drawable.p46,
R.drawable.p47,
R.drawable.p48,
R.drawable.p49,
R.drawable.p50
};
Integer imageId;
TouchImageView touch;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
final Activity act = FullActivity.this;
final AdListener listener = FullActivity.this;
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
imageId = extras.getInt("image");
touch = new TouchImageView(this);
Bitmap snoop = BitmapFactory.decodeResource(getResources(), mThumbIds[imageId]);
touch.setImageBitmap(snoop);
touch.setMaxZoom(4f); //change the max level of zoom, default is 3f
setContentView(touch);
}
final String PREFS_NAME = "AppPrefs";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
int ad = settings.getInt("ad", 0);
if((imageId > 25)&&(ad < 1)){
touch.post(new Runnable() {
public void run(){
myController = new AdController(act, MY_LB_SECTION_ID,
listener);
myController.loadAd();
}
});
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.set_back:
setBack();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void setBack() {
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(mThumbIds[imageId]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(FullActivity.this.getApplicationContext(), "Wallapers set!", Toast.LENGTH_SHORT).show();
}
public void onDestroy(){
myController.destroyAd();
super.onDestroy();
}
public void onAdClicked() {}
public void onAdClosed() {}
public void onAdCompleted() {
// TODO Auto-generated method stub
SharedPreferences settings = getSharedPreferences("AppPrefs", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("ad", 1);
// Commit the edits!
editor.commit();
}
public void onAdFailed() {
this.runOnUiThread(new Runnable() {
public void run() {
if(myController != null){
myController.destroyAd();
}
}
});
}
public void onAdLoaded() {}
public void onAdProgress() {}
}
We have made some adjustments to the code which should resolve this for you.
package com.mkstudio.hdwallpapers;
import java.io.IOException;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import com.Leadbolt.AdController;
import com.Leadbolt.AdListener;
public class FullActivity extends Activity{
private AdController myController;
private String MY_LB_SECTION_ID="729926945";
// references to our images
private Integer[] mThumbIds = {
R.drawable.p1,
R.drawable.p2,
R.drawable.p3,
R.drawable.p4,
R.drawable.p5,
R.drawable.p6,
R.drawable.p7,
R.drawable.p8,
R.drawable.p9,
R.drawable.p10,
R.drawable.p11,
R.drawable.p12,
R.drawable.p13,
R.drawable.p14,
R.drawable.p15,
R.drawable.p16,
R.drawable.p17,
R.drawable.p18,
R.drawable.p19,
R.drawable.p20,
R.drawable.p21,
R.drawable.p22,
R.drawable.p23,
R.drawable.p24,
R.drawable.p25,
R.drawable.p26,
R.drawable.p27,
R.drawable.p28,
R.drawable.p29,
R.drawable.p30,
R.drawable.p31,
R.drawable.p32,
R.drawable.p33,
R.drawable.p34,
R.drawable.p35,
R.drawable.p36,
R.drawable.p37,
R.drawable.p38,
R.drawable.p39,
R.drawable.p40,
R.drawable.p41,
R.drawable.p42,
R.drawable.p43,
R.drawable.p44,
R.drawable.p45,
R.drawable.p46,
R.drawable.p47,
R.drawable.p48,
R.drawable.p49,
R.drawable.p50
};
Integer imageId;
TouchImageView touch;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.full);
Bundle extras = getIntent().getExtras();
if (extras != null) {
imageId = extras.getInt("image");
touch = new TouchImageView(this);
Bitmap snoop = BitmapFactory.decodeResource(getResources(), mThumbIds[imageId]);
touch.setImageBitmap(snoop);
touch.setMaxZoom(4f); //change the max level of zoom, default is 3f
setContentView(touch);
}
final String PREFS_NAME = "SexyRec";
final Activity act = this;
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
int ad = settings.getInt("ad", 0);
if((imageId > 25)&&(ad < 1)){
touch.post(new Runnable() {
public void run(){
myController = new AdController(act, MY_LB_SECTION_ID, new AdListener() {
public void onAdProgress() {
// TODO Auto-generated method stub
}
public void onAdLoaded() {
// TODO Auto-generated method stub
}
public void onAdFailed() {
// TODO Auto-generated method stub
}
public void onAdCompleted() {
// TODO Auto-generated method stub
SharedPreferences settings = getSharedPreferences("SexyRec", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("ad", 1);
// Commit the edits!
editor.commit();
}
public void onAdClosed() {
// TODO Auto-generated method stub
}
public void onAdClicked() {
// TODO Auto-generated method stub
}
});
myController.loadAd();
}
});
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.set_back:
setBack();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void setBack() {
//chuckNorris.setResourceAsWallpaper(mThumbIds[imageId]);
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(mThumbIds[imageId]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(FullActivity.this.getApplicationContext(), "Wallapers set!", Toast.LENGTH_SHORT).show();
}
public void onDestroy(){
myController.destroyAd();
super.onDestroy();
}
}

Categories

Resources