Can't get custom sound on toggle button - audio

Trying to get my toggle buttons to make custom sounds but I just can't get it, I'm very new to eclipse and I managed to get it on the splash screen but can't get it for the buttons.
package org.iimed.www;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ToggleButton;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
public class vpbox extends Activity {
private ImageButton home;
public void onCreate(Bundle vpbox_activity) {
super.onCreate(vpbox_activity);
setContentView(R.layout.vpbox_activity);
tuetoggle = (ToggleButton) findViewById(R.id.tuetoggle);
home = (ImageButton) findViewById(R.id.home);
home.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
startActivity(new Intent(vpbox.this, MainActivity.class));
ToggleButton sb = (ToggleButton) findViewById(R.id.suntoggle);
sb.setText(null);
sb.setTextOn(null);
sb.setTextOff(null);
sb.setBackgroundResource(R.drawable.vpbuttons);
ToggleButton mt= (ToggleButton)findViewById (R.id.montoggle);
mt.setText(null);
mt.setTextOn(null);
mt.setTextOff(null);
mt.setBackgroundResource(R.drawable.vpmonday);
ToggleButton wt = (ToggleButton) findViewById(R.id.wedtoggle);
wt.setText(null);
wt.setTextOff(null);
wt.setTextOn(null);
wt.setBackgroundResource(R.drawable.vpwed);
ToggleButton ft = (ToggleButton) findViewById(R.id.fritoggle);
ft.setText(null);
ft.setTextOn(null);
ft.setTextOff(null);
ft.setBackgroundResource(R.drawable.vpfri);
The test button with the sound:
ToggleButton thb = (ToggleButton) findViewById(R.id.thutoggle);
thb.setText(null);
thb.setTextOn(null);
thb.setTextOff(null);
thb.setBackgroundResource(R.drawable.vpthu);
MediaPlayer mp= MediaPlayer.create(getBaseContext(), R.raw.splashsound);
mp.start();

Related

save last position of videoView saved by sharedprefrence and start in last position (android studio)

save last position of videoView saved by sharedprefrence and start in last position (android studio)
hello I serch for my problam in stackaverflow and other refrences but I dont get my answer
.
I use VideoView In my app
I want to save the last position of videview in a sharedPrefrence to start again from the last position but it start in 0 every time
please check my code and tel me what should i do.
package com.rewass.qurankurdishaudiotranslatev2.activitys;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.rewass.qurankurdishaudiotranslatev2.R;
import com.rewass.qurankurdishaudiotranslatev2.adapters.RecyclerViewAdapter;
import com.rewass.qurankurdishaudiotranslatev2.model.ModelRecycler;
import com.rewass.qurankurdishaudiotranslatev2.text.Text002;
import java.util.ArrayList;
import java.util.List;
public class A002 extends AppCompatActivity {
List<ModelRecycler> listItems;
private InterstitialAd mInterstitialAd;
String AudioURL = "https://download.quranicaudio.com/quran/mishaari_raashid_al_3afaasee/002.mp3";
VideoView videoView;
ProgressBar progressBar008;
TextView te008;
int progress;
RecyclerView myrv;
String kurdish002 = "http://sirwaan.com/aaap/audios/kurdish/sound/quran/qurankurdish/002.mp3";
String v2kurdish002 = "https://sirwaan.com/aaap/audios/kurdish/sound/quran/newversionqurankurdish/002.mp3";
Handler handler;
GridLayoutManager layoutManager;
int seekkk;
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a002);
audioSora();
}
SharedPreferences preferences ;
private void audioSora() {
preferences = getSharedPreferences("pref55",MODE_PRIVATE);
videoView = findViewById(R.id.videoview002);
videoView.setVideoPath(v2kurdish002);
//control media
MediaController mediaController = new MediaController(this);
//set view with controller
videoView.setMediaController(mediaController);
//set Controller to view
mediaController.setAnchorView(videoView);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
SharedPreferences.Editor editor = preferences.edit();
int progress = videoView.getCurrentPosition();
editor.putInt("seekto", progress);
editor.apply();
seekkk = preferences.getInt("seekto", 0);
Toast.makeText(A002.this, seekkk+"", Toast.LENGTH_SHORT).show();
handler.postDelayed(this, 1000); }};
handler.postDelayed(r, 1000);
videoView.seekTo(seekkk);
videoView.start();
}
});
}
}
private int time = 0;
private ScheduledExecutorService mScheduledExecutorService;
Runnable getPositionVideo = () -> {
time = binding.epVideoView.getCurrentPosition();
Log.d(TAG, ": " + time);
};
binding.epVideoView.setOnPreparedListener(mediaPlayer -> {
mediaController.setAnchorView(binding.epVideoView);
binding.epVideoView.start();
mScheduledExecutorService = new ScheduledThreadPoolExecutor(1);
mScheduledExecutorService.scheduleWithFixedDelay(() -> {
runOnUiThread(getPositionVideo);
MediaControllerCustom.init(url, time);
}, 1000, 1000, TimeUnit.MILLISECONDS);
});

Cannot update TextView from another class

My android project has 3 class MainActivity.java , itemlist.java and Bill.java
I created the object of Bill class from itemlist.java class and passed context from there.
So when i try to update textview from Bill.java class it simply does not update but when i do same from MainActivity it works
So my question is how to make this TextView update work?
package com.example.smit.databasedemo.Functions;
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.example.smit.databasedemo.MainActivity;
import com.example.smit.databasedemo.R;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by Smit on 18-02-2020.
*/
public class Bill extends AppCompatActivity{
private LayoutInflater inflater;
private final View view;
public Bill(Context context){
inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.activity_main,null);
}
Here context is passed by using getApplicationContext() passed from MainActivity
public void calculate(String bill){
final TextView billText = (TextView) view.findViewById(R.id.useless);
String text = (billText.getText().toString())+bill;
//Here the text is fetched from same textbox but fail's to update
Pattern p = Pattern.compile("\\d+");
Matcher m = p.matcher(text);
String[] amount= new String[2];
int i=0;
while(m.find()){
amount[i] = m.group();
i++;
}
int amount_prev = Integer.valueOf(amount[0]);
final int total = (amount_prev)+(Integer.valueOf(amount[1]));
billText.setText("Total Bill:"+total+"Rs");
//Cannot update this textbox
}
}
final Bill bill = new Bill(context);
//this is how its called
public void onClick(View v) {
counter++;
price= (finalViewHolder.price.getText().toString());
finalViewHolder.item.setText(String.valueOf(counter));
bill.calculate(price);
}
p.s tried running on uiThread() does not work
You have to pass the Context reference via constructor:
public Bill(Context context){
this.context=context;
//rest of your code...
}
Also find the TextView like this:
TextView billText = (TextView) ((Activity)context).findViewById(R.id.useless);

Notifications wont show android studio

Im trying to get a notification when pressing a button, but it is not showing up. I have followed a lot of tutorials and i think it has something ti do with the version of android. Something with channels. I just dont know how to implement it.
package com.example.root.savetheworldv2;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent =new Intent();
PendingIntent pIntent =
PendingIntent.getActivity(MainActivity.this,0,intent,0);
Notification noti = new
Notification.Builder(MainActivity.this)
.setTicker("TickerTitle")
.setContentTitle("Content Title")
.setContentText("Content Text")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentIntent(pIntent).getNotification();
noti.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager nm =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(0,noti);

Disable JavaFx ComboBox

Correction: this works fine, I was being stupid.
I'm trying to disable a JavaFx ChoiceBox. Thought this would work:
shapeList = FXCollections.observableArrayList(CShape.DOT, CShape.RIGHT_GLIDER, CShape.LEFT_GLIDER);
choiceBox = new ChoiceBox<>(shapeList);
choiceBox.setDisable(true);
but it doesn't seem to.
Everything with disable/enable works just fine. You should provide more of your code to find the flaw.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class ChoiceBoxDisableApp extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
ObservableList<String> items = FXCollections.observableArrayList("one", "two", "three");
ChoiceBox<String> choiceBox = new ChoiceBox<>(items);
Button button = new Button("Disable");
HBox hBox = new HBox(choiceBox, button);
button.setOnMouseClicked(mouseEvent -> {
boolean disable = !choiceBox.isDisabled();
choiceBox.setDisable(disable);
button.setText(disable ? "Enable" : "Disable");
});
stage.setScene(new Scene(hBox));
stage.show();
}
}

Why i get error imageView1 cannot be resolved or is not field?

i get error imageView1 cannot be resolved or is not field. What i have to do? I don't understand. All the code is correct.
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView iv;
private Bitmap bitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.imageView1);
bitmap = getBitmapFromURL("http://icons.iconarchive.com/icons/crountch/one-piece-jolly-roger/72/Luffys-flag-2-icon.png");
iv.setImageBitmap(bitmap);
}

Resources