Posts

Showing posts with the label Android

Message Box Android

public void MsgBox(String title, String msg){ AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle(title); alertDialog.setMessage(msg);  alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int which) {  dialog.dismiss();  }  });  alertDialog.show(); } ========= အသုံးပြုပုံ ၁။ Activity မှာ method တခုအနေနဲ့ ထည့်ထားပါ။ ၂။ MsgBox("Info", "This app is created by Purple Snake.");

Passcode View

https://github.com/hanks-zyh/PasscodeView dependencies {    implementation 'com.hanks:passcodeview:0.1.2'     implementation 'androidx.legacy:legacy-support-v4:1.0.0' } xml ========= <com.hanks.passcodeview.PasscodeView     android:id="@+id/passcodeView"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="#222222"     app:firstInputTip="Enter a passcode"     app:correctStateColor="#71bb4d"     app:wrongStateColor="#ea2b46"     app:normalStateColor="#ffffff"     app:numberTextColor="#222222"     app:passcodeLength="5"     app:passcodeViewType="set_passcode"/> java ========= PasscodeView passcodeView; //id ခေါ်ထား passcodeView.setPasscodeLength(4).setLocalPasscode("1234").setListener(new PasscodeView.PasscodeViewListener(){     @Override     public void onFail(){     } ...

App Updater

https://github.com/KhunHtetzNaing/AppUpdater { "title": "This is Title!", "message": "This is Message", "download": "Direct APK Download Link!!!", "playstore": "com.stmm.app", "uninstall": false, "what": { "model": [], "version": [], "all": true }, "versionName": "1.7", "versionCode": 8, "force": true }

Open Fb page in app

public static Intent getOpenFacebookIntent ( Context context ) { try { context.getPackageManager().getPackageInfo( "com.facebook.katana" , 0 ); return new Intent(Intent.ACTION_VIEW, Uri.parse( "fb://page/<id_here>" )); } catch (Exception e) { return new Intent(Intent.ACTION_VIEW,Uri.parse( "https://www.facebook.com/<user_name_here>" )); } } ============== switch(v.getId()){ case: R.id.btn: startActivity ( getOpenFacebookIntent ()); break; }

Logcat ကြည့်နည်း

Project တခု ရေးပြီး run လိုက်လို့ crash သွားရင် Logcat ကို ဖွင့်ကြည့်ပါ။ အနီရောင် စာသားတွေထဲက Caused by နဲ့ စတဲ့ စာကြောင်း နဲ့ သူ့ရဲ့ အောက်က တလိုင်း ဟာ ဘယ် class, ဘယ် method မှာ ဘာကြောင့် crash သွားတယ် ဆိုတဲ့ အကြောင်းရင်းကို ဖော်ပြပါတယ်။ Logcat မကြည့်တတ်ရင် သင်ဟာ programmer တယောက် မဟုတ်သေးပါဘူး။

Custom Toast

 showToast(Context,"ToastMessage",ToastTextColor(#ffffff),ToastBackgroundColor(#000000));  public static void showToast(Context c,String s, String textcolor, String bgcolor)  {         Toast toast= Toast.makeText(c, "", 0);         toast.setGravity(Gravity.CENTER_VERTICAL, 0, 300);         LinearLayout ne=new LinearLayout(c);         LinearLayout ne2=new LinearLayout(c);         ne2.addView(ne);         LinearLayout.LayoutParams params=(LinearLayout.LayoutParams) ne.getLayoutParams();           params.topMargin = 25;         params.bottomMargin = 25;         params.leftMargin = 50;         params.rightMargin = 50;         ne.setLayoutParams(params);         GradientDrawable drawable=new GradientDrawable();     ...

Play Store မှာ တင်ထားတဲ့ Apk page ကို ဖွင့်နည်း

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appPackageName)));

Webview Downloader

mWebView.setDownloadListener(new DownloadListener(){  public void onDownloadStart(String s,String s1,String s2,String s3,long s4){  //တိုက်ရိုက် download ဆွဲဖို့  Request request = new Request(Uri.parse(s));  request.allowScanningByMediaScanner();  request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);  request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"ProgressBarProject");  DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);  dm.enqueue(request);  //Browser တစ်ခုခုကနေ download ဆွဲဖို့  /*Intent intent=new Intent(Intent.ACTION_VIEW);  intent.setData(Uri.parse(s));  startActivity(intent);*/  }

Prefix && Last

private String getLast(String prefix){ String a=prefix.replaceAll( "," , "" ); int index=a.indexOf( '.' ); int strLength=index- 1 ; return a.substring(strLength,index); } private String getPrefix(String last){ String a=last.replaceAll( "," , "" ); int lastIndex=a.length()- 1 ; int strLength=a.length(); return a.substring(lastIndex,strLength); }

MediaPlayer Android

mp =MediaPlayer. create ( this ,R.raw. covid_song ); mp .start();

Change Action Bar Color Android

ActionBar actionBar = getActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED));

Refresh Button Menu Android

<item android:id="@+id/refresh" android:icon="@drawable/refresh" android:title="Refresh" android:showAsAction="always" />

Action Bar Button Categories Android

<item android:id="@+id/categories" android:icon="@drawable/categories" android:showAsAction="always" android:title="Overflow" > <menu>  <item android:id="@+id/eleven"  android:icon="@drawable/news"  android:title="Eleven" />  <item android:id="@+id/mizzima"  android:icon="@drawable/news"  android:title="Mizzima" />  </menu>  </item>

Button Menu ifRoom Android

<menu xmlns:android="http://schemas.android.com/apk/res/android">   <item   android:id="@+id/news" android:icon="@drawable/news" android:title="News" android:showAsAction="ifRoom|withText" /> </menu> ကျန်တာက Menu add တာက တူတူဘဲ

switch case example Android

switch( v.getId() ){ case R.id.btn: break; }

Android Menu Code

res/menu/main_menu.xml <menu xmlns:android="http://schemas.android.com/apk/res/android">          <item         android:id="@+id/menu1"         android:title="@string/menu1"/> <item         android:id="@+id/menu2"         android:title="@string/menu2"/> <item         android:id="@+id/menu3"         android:title="@string/menu3"/> <item         android:id="@+id/menu4"         android:title="@string/menu4"/> <item         android:id="@+id/menu5"         android:title="@string/menu5"/>      </menu> ===================== res/values/strings.xml <?xml version="1.0" encoding="utf-8"?> <resources>     <string name="app_name">BasicCalculator</string>...

Android Full Screen Code

ActionBar ab=getActionBar(); ab.hide(); // hide title bar requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); // enable full screen

Full Custom Button Color Android

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape> <solid android:color=" #E7FF0B " /> <stroke android:width="0dp" /> <corners android:radius="100dp" /> </shape> </item> <item> <shape> <gradient android:startColor=" #E7FF0B " android:endColor="#1d89" android:angle="270" /> <stroke android:width="3dp" android:color="#f243" /> <corners android:radius="80dp"/> </shape> </item> </selector>

Post protected

<script language="JavaScript"> var password =' pass ' password = prompt('This post protected by admin',''); if(password != ' pass '){ alert("Incorrect Password"); location.href=' https://stmmcoder.blogspot.com/p/bye-by.html '; } </script>

Custom Progressbar Android

<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="4000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > <shape android:innerRadius="20dp" android:shape="ring" android:thickness="4dp" android:useLevel="false" > <size android:height="48dp" android:width="48dp" /> <gradient android:centerColor="#E7FF0B" android:centerY="0.5" android:endColor="#ffec7e2a" android:startColor="#00ec7e2a" android:type="sweep" android:useLevel="false" /> </shape> </rotate> <ProgressBar android:id="@+id/pg_bar" android:layout_width="match_parent" android:l...