I'm Making android App using Seek Bar
Here I was trying to give intervals to a Seek bar in Android.
likewise 0 25 50 100 (i.e it should progress likewise 0 25 50 75 100)
Is it possible? Can any 1 help me?
It will work if you edit the onProgressChanged method like so:
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int stepSize = 25;
progress = (progress/stepSize)*stepSize;
seekBar.setProgress(progress);
sliderText.setText("" + progress);
}
taken tips from here:
Android: Set interval in SeekBar
Related
Currently making a video storage and streaming application. Right now I am trying to add ads to the application. What would be the best way to facilitate video ads for the app? I know that there is a google_mobile_ads package, but due to the guidelines of AdMob, I cannot show multiple video ads in a row. I would like to do something similar to YouTube where a series of 2 ads are shown to the user (in my case, 1 ad for every 30 minutes of content).
What you can do is, when video starts get total video duration and determine how often you want to show ad. Then using a listener keep track of current position and show ad time to time. I have done something like this:
int adEvery = 0;
List<int> adIntervalSeconds = []; //timestamps at which ad will be shown
bool throttle = false;
videoPlayerController.addListener(() {
int durationInSec = chewieController!.videoPlayerController.value.duration.inSeconds;
int positionInSec = chewieController!.videoPlayerController.value.position.inSeconds;
//1500 sec = 25 minutes, isDurationLoaded bool used to make sure it run just once.
if (durationInSec > 1500 && isDurationLoaded == false) {
isDurationLoaded = true;
//if duration > 25 mins then show ad every 20 mins approx.
totalAds = (durationInSec ~/ 1200).toInt();
adEvery = (durationInSec ~/ totalAds).toInt();
//get timestamps in seconds list at which ad should be shown
for (int i = 1; i < totalAds; i++) {
adIntervalSeconds.add(adEvery * i);
}
}
if (videoPlayerController.value.isPlaying &&
adIntervalSeconds.isNotEmpty &&
adIntervalSeconds.contains(positionInSec) &&
throttle == false) {
throttle = true;
Future.delayed(const Duration(seconds: 2), () {
throttle = false;
});
adIntervalSeconds.remove(positionInSec);
showInterstitial();
}
}
This is what I came up with.
When I actually try the game inside Unity everything is fine. When I build the game and try it every resolution is shown twice and they are reversed(ex: 1920 x 1080 is 320 x 200, 1680 x 1050 is 320 x 240 and so on). I will give you my code here:
public Dropdown resolutiondropdown;
Resolution[] resolutions;
void Start()
{
resolutions = Screen.resolutions;
resolutiondropdown.ClearOptions();
int currentresolutionindex = 0;
List<string> options = new List<string>();
for(int i=resolutions.Length-1;i>=0;i--)
{
string option = resolutions[i].width + " x " + resolutions[i].height;
options.Add(option);
if (resolutions[i].width == Screen.width && resolutions[i].height == Screen.height)
currentresolutionindex = i;
}
resolutiondropdown.AddOptions(options);
resolutiondropdown.value = currentresolutionindex;
resolutiondropdown.RefreshShownValue();
}
public void SetResolution(int resolutionindex)
{
Resolution resolution = resolutions[resolutionindex];
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
}
And a screenshot I took:
Settings menu
This dude implement resolution setting in this video, try it out: https://www.youtube.com/watch?v=YOaYQrN1oYQ
So, I cant repeat your problem - your solution also works fine
This it windows default build with your code:
Try to check your 'Resolution and presentation' in Player settings
This is source code of resolution list - unity just takes it from your pc:
/// <summary>
/// <para>All full-screen resolutions supported by the monitor (Read Only).</para>
/// </summary>
public static extern Resolution[] resolutions { [FreeFunction("ScreenScripting::GetResolutions"), MethodImpl(MethodImplOptions.InternalCall)] get; }
Thats why there is only one solution - manually check duplicates and remove it from the list
I have an application that adds one to the score whenever you tap anywhere on the view. I would like to have a score multiplier that states that whenever the user is tapping faster his or her score will not just increment by one, but by a larger amount depending on how fast and/or how long they have been tapping. I've done a good bit of Googling but I have yet to find anything. Thanks in advance
Without further examples its hard to actually give you help, here is a stab
static let multiplier = 1000
struct Player {
var score: Int
var displayScore: Int {
return score * multiplier
}
}
var player = Player(score: 1)
print(player.displayScore) // 1000
player.score += 1
print(player.displayScore) // 2000
I wanted to set an individual interval of sensor events beside:
the given delays: "SENSOR_DELAY_NORMAL, SENSOR_DELAY_U, SENSOR_DELAY_GAME, ENSOR_DELAY_FASTEST".
But non of the "registerListener" methodes seems to support an individual value:
Looking into the implementation of the SensorManager class shows:
public boolean registerListener(SensorEventListener listener, Sensor sensor, int rateUs,
int maxBatchReportLatencyUs) {
int delay = getDelay(rateUs);
return registerListenerImpl(listener, sensor, delay, null,maxBatchReportLatencyUs, 0);
}
private static int getDelay(int rate) {
int delay = -1;
switch (rate) {
case SENSOR_DELAY_FASTEST:
delay = 0;
break;
case SENSOR_DELAY_GAME:
delay = 20000;
break;
case SENSOR_DELAY_UI:
delay = 66667;
break;
case SENSOR_DELAY_NORMAL:
delay = 200000;
break;
default:
delay = rate;
break;
}
return delay;
}
Is there realy no way to set an individual value for the sensor event interval?
SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, etc are all simply integers, as shown in your code. Saying you want SENSOR_DELAY_UI is the same as telling the sensor manager to use an interval of 66667 microseconds. However, per the docs, you can simply input your own interval in that field:
The desired delay between two consecutive events in microseconds. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. Can be one of SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, SENSOR_DELAY_GAME, SENSOR_DELAY_FASTEST or the delay in microseconds.
However, it's important to note the other part of that quote:
...The desired delay between two consecutive events in microseconds. This is only a hint to the system....
At the end of the day, it's just a suggestion and the Android system doesn't seem to be too good about respecting your request. If you really care about the interval I would suggest adding a method in your callback that checks the time delta between now and the last time you recorded a sensor value and then only recording it if its been sufficiently long.
Source: Android Link
You can simply use a Timer and a boolean flag to handle this problem:
imagine you want to check sensor event values every 1 seconds(for example):
boolean mustReadSensor;
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
mustReadSensor = true;
}
}, 0, 1000); // 1000 ms delay
and here is onSensorChanged:
#Override
public void onSensorChanged(SensorEvent event) {
if (!mustReadSensor) {
return;
}
mustReadSensor = false;
//handle sensor values here
}
I'm trying to develop an android application which should take continuous images just like native camera in continuous shooting mode for 10 to 20 seconds.
I followed the sample program from the site
http://marakana.com/forums/android/examples/39.html
Now , i want to enhance this code to take continuous images (for 10 to 20 seconds) ,
first i tried to take 10 pics by using a for loop ,
i just put the takePicture() function in the loop , but that'S not working .
do i need to use threadS .
IF YES , THEN which part should i put in thread , the image capturing or image saving to
sd card
If any body having some sample code for taking continuous images , pls share.
Just put a counter in the jpegCallBack function, that decrements and calls your takePicture() again until the wished number of pictures is reached.
int pictureCounter = 10;
PictureCallback jpegCallback = new PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
// save your picture
if(--pictureCounter>=0) {
takePicture();
} else {
pictureCounter = 10; // reset the counter
}
}
I know it is very late to reply, but I just came across this question and thought it would be helpful for future visitors.
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
//Save Picture here
preview.camera.stopPreview();
// if condition
preview.camera.startPreview();
// end if condition
}
};