sábado, 27 de fevereiro de 2016

Inserir o seguinte código no local desejado para realizar a ação:

 <% if user_signed_in? %>  
  <li>  
  <%= link_to('Logout', destroy_user_session_path, :method => :delete) %>      
  </li>  
 <% else %>  
  <li>  
  <%= link_to "Sign in", new_user_registration_path %>  
  </li>  
  <li>  
  <%= link_to "Sign up", new_user_session_path %>  
  </li>  
 <% end %> 

Inserir o seguinte código no arquivo 'config/initializers/devise.rb':


 config.sign_out_via = :get  

sábado, 13 de fevereiro de 2016

Android: Como colocar um DatePicker no edittext

edtData.setInputType(InputType.TYPE_NULL);  
     edtData.setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(View v) {  
         Calendar newCalendar = Calendar.getInstance();  
         DatePickerDialog fromDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {  
           public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {  
             SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);  
             Calendar newDate = Calendar.getInstance();  
             newDate.set(year, monthOfYear, dayOfMonth);  
             edtData.setText(dateFormatter.format(newDate.getTime()));  
           }  
         },newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));  
         fromDatePickerDialog.show();  
       }  
     });  

quarta-feira, 25 de novembro de 2015

Convertendo String em Bitmap e vice versa

 public static String BitMapToString(Bitmap bitmap){  
     ByteArrayOutputStream baos=new ByteArrayOutputStream();  
     bitmap.compress(Bitmap.CompressFormat.PNG,0, baos);  
     byte [] b=baos.toByteArray();  
     String temp= Base64.encodeToString(b, Base64.DEFAULT);  
     return temp;  
   }  
   public static Bitmap StringToBitMap(String encodedString){  
     try{  
       byte [] encodeByte=Base64.decode(encodedString,Base64.DEFAULT);  
       //Bitmap bitmap= BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);  
       //return bitmap;  
       BitmapFactory.Options options=new BitmapFactory.Options();// Create object of bitmapfactory's option method for further option use  
       options.inPurgeable = true; // inPurgeable is used to free up memory while required  
       Bitmap songImage1 = BitmapFactory.decodeByteArray(encodeByte,0, encodeByte.length,options);//Decode image, "thumbnail" is the object of image file  
       Bitmap songImage = Bitmap.createScaledBitmap(songImage1, 300 , 300 , true);// convert decoded bitmap into well scalled Bitmap format.  
       return songImage;  
     }catch(Exception e){  
       e.getMessage();  
       return null;  
     }  

sábado, 17 de janeiro de 2015

Conseguir o keyhash do facebook para android, erro openssl não é reconhecido como comando interno (Windows)

Para conseguir gerar um key hash para desenvolver aplicativos android utilizando a lib do facebook pode ocorrer um erro dizendo que " 'openssl' não é reconhecido como um comando interno". Para resolver isso basta fazer download do openssl, extrair os arquivos dentro da pasta .android e no comando inserir o caminho do arquivo openssl.exe e executar o comando normalmente.

Ex:  keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | C:\Users\chico\.android\openssl sha1 -binary | C:\Users\chico\.android\openssl base64

quarta-feira, 5 de novembro de 2014

Como acessar as pastas e subpastas de um diretorio em Java

public void listf(String directoryName, ArrayList<File> files) {
    File directory = new File(directoryName);

    // get all the files from a directory
    File[] fList = directory.listFiles();
    for (File file : fList) {
        if (file.isFile()) {
            files.add(file);
        } else if (file.isDirectory()) {
            listf(file.getAbsolutePath(), files);
        }
    }
}

segunda-feira, 27 de outubro de 2014

Confirm Dialog usando Java Swing

Código para ser inserido quando se deseja mostrar uma janela que receba a confirmação do usuário para dar continuidade a ação.


int dialogButton = JOptionPane.YES_NO_OPTION;
int dialogResult = JOptionPane.showConfirmDialog(this, "Your Message", "Title on Box",dialogButton);
if(dialogResult==0)
  System.out.println("Yes option");
else
 System.out.println("No Option");

domingo, 12 de outubro de 2014

Java - Lendo caracteres

public void lerArquivo(){
String nome = "code.txt";
char letra;
try {
FileReader arq = new FileReader(nome);
BufferedReader lerArq = new BufferedReader(arq);
//String linha = lerArq.readLine();
// lê a primeira linha
// a variável "linha" recebe o valor "null" quando o processo
// de repetição atingir o final do arquivo texto
letra = (char) lerArq.read();
int c;
while ((c = lerArq.read()) != -1) {
//System.out.printf("%s\n", linha);
//linha = lerArq.readLine();

//letra = (char) lerArq.read();
c = lerArq.read();
System.out.println(c);
System.out.printf(" OI %c\n",(char)c);
// lê da segunda até a última linha
}
arq.close();
} catch (IOException e) {
String local = System.getProperty("user.dir");
System.err.printf("Erro na abertura do arquivo: %s.\n", e.getMessage()+" "+local);
}
}