Postingan

Menampilkan postingan dengan label Tools Code

Tools - Screen Orientation

//Lanscape Mode setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //Portrait Mode setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Tools - AddView Widget

/*   *   * if you use in mainactivity use:   * return this.getWindow().getDecorView().findViewById(android.R.id.content);   *   */ final Button mybtn = new Button(this); mybtn.setText("Your Button"); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT); #Add ((ViewGroup) getActivityContentView()).addView(mybtn, layoutParams); #Remove ((ViewGroup) getActivityContentView()).removeView(mybtn); } public View getActivityContentView() { try { return ((Activity) getContext()).getWindow().getDecorView().findViewById(android.R.id.content); } catch(ClassCastException e) { throw new ClassCastException("Please provide an Activity context for this FloatingActionButton."); } }{

Tools - AsynTask Source URL

new BackTask().execute("URL"); } private class BackTask extends AsyncTask<String, Integer, String> { @Override protected void onPreExecute() { } protected String doInBackground(String... address) { String output = ""; try { java.net.URL url = new java.net.URL(address[0]); java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(url.openStream())); String line; while ((line = in.readLine()) != null) { output += line; } in.close(); } catch (java.net.MalformedURLException e) { output = e.getMessage(); } catch (java.io.IOException e) { output = e.getMessage(); } catch (Exception e) { output = e.toString(); } return output; } protected void onProgressUpdate(Integer... values) { } protected void onPostExecute(String s){ textview1.setText(s); } } {

Tools - Auto Generated ID

//Generate ID private static final java.util.concurrent.atomic.AtomicInteger sNextGeneratedId = new java.util.concurrent.atomic.AtomicInteger(1); public static int generateViewId() {     for (;;) {         final int result = sNextGeneratedId.get();         // aapt-generated IDs have the high byte nonzero; clamp to the range under that.         int newValue = result + 1;         if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.         if (sNextGeneratedId.compareAndSet(result, newValue)) {             return result;         }     } } //use if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { myView.setId(Utils.generateViewId()); } else { myView.setId(View.generateViewId()); }

Tools Background Task

//Used to run your app in background like you click the home button moveTaskToBack(true);

Tools - Clear Cache

} public static void deleteCache(Context context) {     try {         java.io.File dir = context.getCacheDir();         deleteDir(dir);     } catch (Exception e) {        e.printStackTrace();        showMessage(e.toString());     } } public static boolean deleteDir(java.io.File dir) {     if (dir != null && dir.isDirectory()) {         String[] children = dir.list();         for (int i = 0; i < children.length; i++) {             boolean success = deleteDir(new java.io.File(dir, children[i]));             if (!success) {                 return false;             }         }         return dir.delete();     } else if(dir!= null && dir....

Tools - enclosing

MainActivity myActivity = new MainActivity(); MainActivity.parseYouTubeAndYahoo asyncTask = myActivity.new parseYouTubeAndYahoo();

Tools - Error Deprecation

@SuppressWarnings("deprecation")

Tools - Get Package

public class _getPackageName { private String _package = ""; public String _get() { _getPackageName _o = new _getPackageName(); Package _pack = _o.getClass().getPackage(); String _packageName = _pack.getName(); return _package = _packageName; } public String _getPackage() { if (_package.equals("")) { _get(); return _package; } else { return _package; } } }

Tools - Get Version Code/Name

//Create variable versionName and versionCode String versionName = "null"; int versionCode = -1; try { android.content.pm.PackageInfo packageInfo = MainActivity.this.getPackageManager().getPackageInfo(getPackageName(), 0); versionName = packageInfo.versionName; versionCode = packageInfo.versionCode; } catch (android.content.pm.PackageManager.NameNotFoundException e) { e.printStackTrace(); } //textview set text TextView textViewVersionInfo = (TextView) findViewById(R.id.textview1); textViewVersionInfo.setText(String.format("Version Name: %s Version Code:%d", versionName, versionCode));

Tools - Get Clipboard

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); String clipboard_text = clipboard.getText().toString(); textview1.setText(clipboard_text);

Tools - Notification

//Generate Alert Feature Notification.Builder mBuilder = new Notification.Builder(MainActivity.this); mBuilder.setSmallIcon(R.drawable.appicon); mBuilder.setContentTitle("You're Title"); mBuilder.setContentText("You're Text"); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int onx = 1; notificationManager.notify(onx, mBuilder.build()); //Run activity and create alert notification Notification.Builder mBuilder = new Notification.Builder(MainActivity.this); mBuilder.setSmallIcon(R.drawable.appicon); mBuilder.setContentTitle("You're Title"); mBuilder.setContentText("You're Text"); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent( getApplicationContext(), SwwActivity.class); PendingIntent p...

Tools - Print

java.lang.System.setOut(new java.io.PrintStream(new java.io.OutputStream() { java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream(); @Override public void write(int oneByte) throws java.io.IOException { outputStream.write(oneByte); textview1.setText(new String(outputStream.toByteArray())); } })); //Testing the System.out stream java.lang.System.out.println("Test"); java.lang.System.out.println("Test 2");

Tools - Print Method

public void Function(String _str) { try { Class<?> c = Class.forName(_str); System.out.println("name = " + c.getName()); System.out.println("package = " + c.getPackage()); java.lang.reflect.Method[] methods = c.getDeclaredMethods(); System.out.println("----- Class methods ---------------"); for (java.lang.reflect.Method method : methods) { System.out.println(method.getName()); } } catch (ClassNotFoundException e) { e.printStackTrace(); } }

Tools - Read Resources

java.io.InputStream ins = getResources().openRawResource(R.drawable.file); StringBuilder text = new StringBuilder(); try {     java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(ins));     String line;     while ((line = br.readLine()) != null) {         text.append(line);         text.append('n');     }     br.close(); } catch (java.io.IOException e) { } EditText tv = (EditText)findViewById(R.id.edittext1); tv.setText(text.toString());

Tools - Runnable Example

void startTime(){ handler.postDelayed(runnable, 1000); } int totalDelay=0; Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { totalDelay++; if(totalDelay<=20){ handler.postDelayed(runnable, 1000); } textview1.setText(totalDelay+" Second"); } };

Tools - Screen Brightness

WindowManager.LayoutParams layout = getWindow().getAttributes(); layout.screenBrightness = 0.5F ; getWindow().setAttributes(layout); // 0.5 is %50 // 1 is %100

Tools - Share Apk File

String apk = ""; String uri = ("com.my.project"); try { android.content.pm.PackageInfo pi = getPackageManager().getPackageInfo(uri, android.content.pm.PackageManager.GET_ACTIVITIES); apk = pi.applicationInfo.publicSourceDir; } catch (Exception e) { showMessage(e.toString()); } Intent iten = new Intent(Intent.ACTION_SEND); iten.setType("*/*"); iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(apk))); startActivity(Intent.createChooser(iten, "Send APK"));

Tools - Speech to Text

//Set onCreate } private final int REQ_CODE_SPEECH_INPUT=100; private void sowhat() { //Set on moreblock "speech" Intent intent = new Intent(android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL, android.speech.RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); intent.putExtra(android.speech.RecognizerIntent.EXTRA_PROMPT, "Say something"); try { startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); } catch (ActivityNotFoundException a) { Toast.makeText(getApplicationContext(), "Your device doesn't support speech input", Toast.LENGTH_SHORT).show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQ_CODE_SPEECH_INPUT: { if (resultCode == RESULT_OK && null != data) { Ar...

Tools - Split Array

list.addAll(Arrays.asList(string_value_with_array_code.split(", /* WHERE IT SHOULD BE SPLIT AT */")));

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

TextInputLayout in Sketchware

How to enable download in webview in Sketchware apps?

Create Stopwatch App in Android using Sketchware

Code for implementing Notifications in Sketchware

A Flash Light App in Sketchware

Codes for modifying Action Bar in Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

How to find and​ highlight a word in a text field in Sketchware?

Firebase Login/Register with email verification