my code stock.com

Snippet options

Download: Download snippet as bluwif-backup-792015.java.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

package com.example.bluwif;


import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.camera2.*;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CircularSeekBar;
import android.widget.CircularSeekBar.OnSeekChangeListener;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	
	static boolean new_value=false;
	static boolean isFlashlightOn=false;
	static  boolean runnable_running=false;
	static boolean switch_button=false;
	
	static int frum_timer,temp_timer;
	static boolean params_on=false;
	ProgressBar progress;
	SeekBar seekbar;
	
	String out_string;
	String value_send;
	
	EditText textfield, timer_field;
	
	TextView simple_text, frumtimer_stats,text_view, params_text;
	static TimerTask timetask;
	static Timer timer;
	Parameters cameraParams;
	private Camera camera;
	CircularSeekBar circularSeekbar;
	
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	
		
		setContentView(R.layout.activity_second);
		/////////
		final CountDownTimer here_refresh;
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		 
		//timer_field = (EditText)findViewById(R.id.timer_field);
		final Button aprinde =(Button)findViewById(R.id.aprinde);
		
		Button refresh = (Button)findViewById(R.id.refresh_butt);
		
		simple_text= (TextView)findViewById(R.id.simple_text);
		
		frumtimer_stats = (TextView)findViewById(R.id.frumtimer_stats);
		progress = (ProgressBar) findViewById(R.id.progressBar1);
		seekbar = (SeekBar)findViewById(R.id.circularSeekbar);
		seekbar.setVisibility(View.GONE);
		
		
		final Runnable runnable;
		
		camera = Camera.open();
		
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
			     .detectAll()
			     .penaltyLog()
			     .build();
			 StrictMode.setThreadPolicy(policy);
			
			 final ourHTTP hi = new ourHTTP();
			
			 // getting interval info from site on every 2 sec
			 frum_timer=1000;
			 
			 /*circularSeekbar = new CircularSeekBar(this);
		        circularSeekbar.setMaxProgress(100);
		        circularSeekbar.setProgress(100);
		        circularSeekbar.setBarWidth(20);
		        
		        setContentView(circularSeekbar);
		        circularSeekbar.invalidate();
			 
		        
		        circularSeekbar.setSeekBarChangeListener(new OnSeekChangeListener() {

		            public void onProgressChange(CircularSeekBar view, int newProgress) {
		                Log.d("Welcome", "Progress:" + view.getProgress() + "/" + view.getMaxProgress());
		            }
		        });    
			*/
	here_refresh = new CountDownTimer(160000,2000){																
		public void onTick(long millisUntilFinished){
								
			
			frumtimer_stats.setText("Reresh remaining:"+ millisUntilFinished/1000);
			out_string = hi.getWebPage("http://daniandroid.hol.es/register.php");  //getting interval value from site [ex. 500] which means 500 ms
			 //frum_timer = Integer.parseInt(out_string.replaceAll("[\\D]","")); 
		      frum_timer = Integer.parseInt(out_string);  //converts the interval to int
		  			
		if(frum_timer==temp_timer) //checking if there's a new value
			{
											
			new_value = false;  // 	
				}
				else
				{
					new_value = true;    //checking if there's a new value
											
					temp_timer = frum_timer; 					
			}

				}
			public void onFinish()
			{
				
			}
			}.start();
			here_refresh.start();
			
			seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
				int progressChanged = 0;
				public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
					progressChanged = progress;
				}
				public void onStartTrackingTouch(SeekBar seekBar) {
					// TODO Auto-generated method stub
				}
				public void onStopTrackingTouch(SeekBar seekBar) {
					runOnUiThread(new Runnable() {

		    	 @Override
		    	 public void run() {
		    		    	
		    	Toast.makeText(getApplicationContext(), "Sending: ["+progressChanged*15+"]", Toast.LENGTH_SHORT).show();;
		    	String sendvalue= String.valueOf(progressChanged*15);
		    	//seekbar.getProgressDrawable().setColorFilter(Color.RED,Mode.SRC_IN);;
		    	hi.sendToServer(sendvalue);
		    		            }
		    	 });
					
				}
			});
			
			 runnable = new Runnable() {
			      @Override
			      public void run() {
			        for (int i = 1; i <= 50; i++) {
			          final int value = i;
			          if(frum_timer ==0)
			          { return; }
			         runnable_running=true;
			        
			         if(switch_button==true){
			           doFakeWork(frum_timer);
			           if(i==50)
			           {
			        	   runnable_running=false;
			        	   force_stop_led();
			           }
			         }
			           progress.post(new Runnable() {
			               @Override
			               public void run() {
			            	   progress.setMax(50);
			                 progress.setProgress(value);
			               }
			             });
			   
			        }
			      }
			    };		
	
			    
	 new CountDownTimer(160000,400)
			    {

					@Override
					public void onTick(long millisUntilFinished) {
						
						if(!runnable_running)
						{
							new Thread(runnable).start();
						}
					}

					@Override
					public void onFinish() {
						// TODO Auto-generated method stub
						
					}
			    	
			    	
			    }.start();
			    
			    
			   
			
			
			
			
			 
			
		refresh.setOnClickListener(new View.OnClickListener() {
						
			@Override
			public void onClick(View v) {
				
				here_refresh.cancel();
				here_refresh.start();
				 //ourHTTP bob = new ourHTTP();
				//bob.sendToServer("register");
			}
		});

		
		refresh.setOnLongClickListener(new View.OnLongClickListener() {
			
			@Override
			public boolean onLongClick(View v) {
				
				
				seekbar.setVisibility(View.VISIBLE);
				Toast.makeText(getApplicationContext(), "Acces granted!", Toast.LENGTH_SHORT).show();;
				return false;
			}
		});
		
			
					
	 aprinde.setOnClickListener(new View.OnClickListener() {
							
		@Override
		public void onClick(View v) {
			
			if(switch_button==false)
			{
				aprinde.setBackgroundResource(R.drawable.turnoff);
				switch_button=true;
			}
			else
			{
				aprinde.setBackgroundResource(R.drawable.turnon);
				switch_button=false;
				
			}
			
		}
		});
				


			
	}
	





private void doFakeWork(int myfrum) {
	
	if(myfrum != 0){
    try {
    	
    	 
    	Thread.sleep(myfrum);
    	start_Activity();
    	 runOnUiThread(new Runnable() {

    		    @Override
    		    public void run() {
    		    	simple_text.setText("Interval[ms]:"+ frum_timer);
    		            }
    	 });
      
    }catch (InterruptedException e) {
      e.printStackTrace();
    }
	}
  }

@SuppressWarnings("deprecation")
public void start_Activity(){

	if(isFlashlightOn==false)
	{
		isFlashlightOn = true;
		params_on= true;
		if (camera ==null){ return; }
		
	cameraParams = camera.getParameters();
    cameraParams.setFlashMode(Parameters.FLASH_MODE_TORCH);
    camera.setParameters(cameraParams);
    camera.startPreview(); 
   
    
	}
	else
	{
		isFlashlightOn = false;
		 params_on = false;
		if (camera ==null){ return; }
		 	cameraParams.setFlashMode(Parameters.FLASH_MODE_OFF);
	        camera.setParameters(cameraParams);
	        camera.stopPreview();
	
	        force_stop_led();
	        
	}

	
}




public void force_stop_led()
{
	
	if (camera ==null){ return; }
	cameraParams.setFlashMode(Parameters.FLASH_MODE_OFF);
    camera.setParameters(cameraParams);
    camera.stopPreview(); 
    //camera.release();
	
}




}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.