Back to project page BanglaFontInstaller.
The source code is released under:
GNU General Public License
If you think the Android project BanglaFontInstaller listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.krossware.banglafontinstaller; //from w ww .j a v a 2s.c om import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.app.Activity; import android.app.AlertDialog; import android.app.Fragment; import android.content.DialogInterface; import android.content.res.AssetManager; import android.os.Bundle; import android.os.Environment; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.Toast; import com.krossware.banglafontinstaller.FontHelper; import com.krossware.banglafontinstaller.ExecuteAsRootBase; public class MainActivity extends Activity { @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); applyFonts(); if (!ExecuteAsRootBase.canRunRootCommands()) { AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this); dlgAlert.setMessage("Sorry, your device is not rooted. This app is unable to work on this device."); dlgAlert.setTitle("Not Rooted"); dlgAlert.setPositiveButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }); dlgAlert.setCancelable(true); dlgAlert.create().show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()).commit(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() {} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); return rootView; } } public void applyFonts() { // FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.RelativeLayout1), "SolaimanLipi.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutAdorshoLipi), "AdorshoLipi.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutAkash), "Akash.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutAponaLohit), "AponaLohit.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutBensen), "BenSen.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutBensenHandwriting), "BenSenHandwriting.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutKalpurush), "Kalpurush.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutLohit), "Lohit.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutMitraMono), "Mitra.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutMukti), "Mukti.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutMuktiNarrow), "MuktiNarrow.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutSiyamRupali), "SiyamRupali.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutSolaimanLipi), "SolaimanLipi.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutSagor), "Sagar.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutNikoshLightBan), "NikoshLightBan.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutNikoshLight), "NikoshLight.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutNikoshGrameen), "NikoshGrameen.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutNikoshBAN), "NikoshBAN.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutNikosh), "Nikosh.ttf"); FontHelper.applyFont(getApplicationContext(), (LinearLayout) findViewById(R.id.layoutBangla), "Bangla.ttf"); } public void runRootCmd(String command) { Process p; try { p = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(p.getOutputStream()); os.writeBytes(command + "\n"); os.writeBytes("exit\n"); os.flush(); } catch (Exception e) { e.printStackTrace(); } } public void toastMessage(String message) { Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); } private void copyAsset(String filename) { AssetManager assetManager = getAssets(); InputStream in = null; OutputStream out = null; try { in = assetManager.open(filename); out = new FileOutputStream(getApplicationContext().getCacheDir() + filename); copyFile( in , out); in .close(); in = null; out.flush(); out.close(); out = null; } catch (IOException e) { toastMessage("Copy failed"); Log.e("tag", "Failed to copy asset file: " + filename, e); } } private void copyFile(InputStream in , OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read; while ((read = in .read(buffer)) != -1) { out.write(buffer, 0, read); } } public void installFont(View view) { String filename = ""; switch (view.getId()) { case R.id.installAponaLohit: filename = "AponaLohit.ttf"; break; case R.id.installSolaimanLipi: filename = "SolaimanLipi.ttf"; break; case R.id.installSagar: filename = "Sagar.ttf"; break; case R.id.installNikoshLightBan: filename = "NikoshLightBan.ttf"; break; case R.id.installNikoshLight: filename = "NikoshLight.ttf"; break; case R.id.installNikoshGrameen: filename = "NikoshGrameen.ttf"; break; case R.id.installNikoshBAN: filename = "NikoshBAN.ttf"; break; case R.id.installNikosh: filename = "Nikosh.ttf"; break; case R.id.installMitra: filename = "Mitra.ttf"; break; case R.id.installLohit: filename = "Lohit.ttf"; break; case R.id.installMuktiNarrow: filename = "MuktiNarrow.ttf"; break; case R.id.installMukti: filename = "Mukti.ttf"; break; case R.id.installKalpurush: filename = "Kalpurush.ttf"; break; case R.id.installBenSenHandwriting: filename = "BenSenHandwriting.ttf"; break; case R.id.installBenSen: filename = "BenSen.ttf"; break; case R.id.installBangla: filename = "Bangla.ttf"; break; case R.id.installAkash: filename = "Akash.ttf"; break; case R.id.installAdorshoLipi: filename = "AdorshoLipi.ttf"; break; case R.id.installSiyamRupali: filename = "SiyamRupali.ttf"; break; } final String Finalfilename = filename; AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this); dlgAlert.setMessage("Are you sure you want to install this font? The phone will reboot to complete installation."); dlgAlert.setTitle("Install " + Finalfilename + "?"); dlgAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { copyAsset(Finalfilename); String[] toBeExecuted = { "mount -o remount,rw /system", "rm" + " " + "/system/fonts/DroidSansFallback.ttf", "rm" + " " + "/system/fonts/Lohit-Bengali.ttf", "rm" + " " + "/system/fonts/NotoSansBengali-Regular.ttf", "rm" + " " + "/system/fonts/NotoSansBengaliUI-Regular.ttf", "cp" + " " + getApplicationContext().getCacheDir() + Finalfilename + " " + "/system/fonts/DroidSansFallback.ttf", "cp" + " " + getApplicationContext().getCacheDir() + Finalfilename + " " + "/system/fonts/Lohit-Bengali.ttf", "cp" + " " + getApplicationContext().getCacheDir() + Finalfilename + " " + "/system/fonts/NotoSansBengali-Regular.ttf", "mv" + " " + getApplicationContext().getCacheDir() + Finalfilename + " " + "/system/fonts/NotoSansBengaliUI-Regular.ttf", "chmod" + " " + "644" + " " + "/system/fonts/DroidSansFallback.ttf", "chmod" + " " + "644" + " " + "/system/fonts/Lohit-Bengali.ttf", "chmod" + " " + "644" + " " + "/system/fonts/NotoSansBengali-Regular.ttf", "chmod" + " " + "644" + " " + "/system/fonts/NotoSansBengaliUI-Regular.ttf", "mount -o remount,ro /system", "reboot" }; ExecuteAsRootBase.execute(toBeExecuted); toastMessage("Installed " + Finalfilename + "!"); } }); dlgAlert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { toastMessage("Installation aborted"); } }); dlgAlert.setCancelable(true); dlgAlert.create().show(); } }