i have 2 EditText and 4 button.and i need when, user clicked on first button, (from edittext1), output string sended in edit text2 and then, i can copyed output string in clipboard on android. this is my try in MainActivity :
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public class MainActivity extends Activity {
Button copy,paste;
EditText copyTxt;
TextView pasteTxt;
int sdk = android.os.Build.VERSION.SDK_INT;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
copy = (Button)findViewById(R.id.copy);
copyTxt = (EditText)findViewById(R.id.copytxt);
copy.setOnClickListener(new View.OnClickListener() {
String CopyText;
@SuppressWarnings("deprecation")
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
CopyText = copyTxt.getText().toString();
if(CopyText.length() != 0){
if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(CopyText);
Toast.makeText(getApplicationContext(), "Text Copied to Clipboard", Toast.LENGTH_SHORT).show();
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Clip",CopyText);
Toast.makeText(getApplicationContext(), "Text Copied to Clipboard", Toast.LENGTH_SHORT).show();
clipboard.setPrimaryClip(clip);
}}else{
Toast.makeText(getApplicationContext(), "Nothing to Copy", Toast.LENGTH_SHORT).show();
}
Button b = (Button) findViewById(R.id.button2);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, BruteForceActivity.class));
}
});
Button b1 = (Button) findViewById(R.id.aboutbtn);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog d = new Dialog(MainActivity.this);
d.setContentView(R.layout.dialog);
String title = getResources().getString(R.string.dialog_title);
d.setTitle(title);
d.show();
}
});
//for Showing Dialog.
final Button bb = (Button) findViewById(R.id.button1);
bb.setOnClickListener(new OnClickListener() {
@SuppressLint("ShowToast")
@Override
public void onClick(View v) {
EditText et = (EditText) findViewById(R.id.editText1);
String editText_input = et.getText().toString();
//Save to String-Name = editText_input
String rawString = et.getText().toString();
try {
Toast.makeText(MainActivity.this, "It's Done !", 2000).show();
EditText editText2 = (EditText) findViewById(R.id.editText2);
editText2.setText(AeSimpleMD5.MD5(rawString));
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//need to showing that in editText2.
}
});
}
}
class AeSimpleMD5 {
private static String convertToHex(byte[] data) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
int halfbyte = (data[i] >>> 4) & 0x0F;
int two_halfs = 0;
do {
if ((0 <= halfbyte) && (halfbyte <= 9))
buf.append((char) ('0' + halfbyte));
else
buf.append((char) ('a' + (halfbyte - 10)));
halfbyte = data[i] & 0x0F;
} while (two_halfs++ < 1);
}
return buf.toString();
}
public static String MD5(String text) throws NoSuchAlgorithmException,
UnsupportedEncodingException {
MessageDigest md;
md = MessageDigest.getInstance("MD5");
byte[] md5hash = new byte[32];
md.update(text.getBytes("iso-8859-1"), 0, text.length());
md5hash = md.digest();
return convertToHex(md5hash);
}
}
}
}}
i used this tutorial for adding clipboard :
http://www.learn2crack.com/2014/01/android-using-clipboard-copy-paste-data.html
i need just, when user clicked on first button, output (md5 hash) sended in textedit2,
and user can copyed in clipboard with Copy(Button). also, i used class AeSimpleMD5 for md5 hash
http://www.anyexample.com/programming/java/java_simple_class_to_compute_md5_hash.xml
.i cant fixed the clipboard. please help.
0 comments:
Post a Comment