Sunday, 11 December 2016

Android How to change language programaticaly



Android How to change language programaticaly


Hello Friends

This My new blog . Here i am simply explain you how to change language programaticaly in you app .

just simple step are below




1. prepair a string resource for the four language (English , hindi , marathi , russian)

  1. <resources>
  2. <string name="app_name">ChangeLocaleExample</string>
  3. <string name="hello_world">Hello World</string>
  4. <string name="btn_en">English</string>
  5. <string name="btn_ru">Russian</string>
  6. <string name="btn_de">German</string>
  7. <string name="btn_fr">French</string>
  8. </resources>



Source code values-ru/strings.xml (Russian)

  1. <resources>
  2. <string name="hello_world">Привет, Мир</string>
  3. <string name="btn_en">Английский</string>
  4. <string name="btn_ru">Русский</string>
  5. <string name="btn_de">Немецкий</string>
  6. <string name="btn_fr">Французский</string>
  7. </resources>



  1. Source code values-hi/strings.xml (Hindi)

  2. <resources>
  3. <string name="hello_world">नमस्ते दुनिया</string>
    <string name="btn_en">अंग्रेज़ी</string>
    <string name="btn_ru">Russisch</string>
    <string name="btn_de">हिंदी</string>
    <string name="btn_fr">मराठी</string>
  4. </resources>
  5. Source code values-de/strings.xml (marathi)
  6. <resources>
  7. <string name="hello_world">हॅलो जग</string>
    <string name="btn_en">इंग्रजी</string>
    <string name="btn_ru">Russisch</string>
    <string name="btn_de">हिंदी</string>
    <string name="btn_fr">मराठी</string>
  8. </resources>




step 2 :

Creat resource file with 4 button and 1 textview


  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:id="@+id/txt_hello"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:layout_weight="1"
  11. android:gravity="center"
  12. android:text="@string/hello_world" />
  13. <LinearLayout
  14. android:layout_width="match_parent"
  15. android:layout_height="wrap_content"
  16. android:layout_weight="1"
  17. android:orientation="horizontal"
  18. android:gravity="center">
  19. <Button
  20. android:id="@+id/btn_en"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:layout_weight="1"
  24. android:text="@string/btn_en" />
  25. <Button
  26. android:id="@+id/btn_ru"
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:layout_weight="1"
  30. android:text="@string/btn_ru" />
  31. <Button
  32. android:id="@+id/btn_de"
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"
  35. android:layout_weight="1"
  36. android:text="@string/btn_de" />
  37. <Button
  38. android:id="@+id/btn_fr"
  39. android:layout_width="wrap_content"
  40. android:layout_height="wrap_content"
  41. android:layout_weight="1"
  42. android:text="@string/btn_fr" />
  43. </LinearLayout>
  44. </LinearLayout>





Step 3 -

main activity code
(MainActivity.java)

  1. public class MainActivity extends AppCompatActivity implements View.OnClickListener{
  2. private TextView txt_hello;
  3. private Button btn_en, btn_ru, btn_fr, btn_de;
  4. private Locale myLocale;
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9. this.txt_hello = (TextView)findViewById(R.id.txt_hello);
  10. this.btn_en = (Button) findViewById(R.id.btn_en);
  11. this.btn_ru = (Button) findViewById(R.id.btn_ru);
  12. this.btn_fr = (Button)findViewById(R.id.btn_fr);
  13. this.btn_de = (Button)findViewById(R.id.btn_de);
  14. this.btn_en.setOnClickListener(this);
  15. this.btn_ru.setOnClickListener(this);
  16. this.btn_fr.setOnClickListener(this);
  17. this.btn_de.setOnClickListener(this);
  18. loadLocale();
  19. }
  20. public void loadLocale()
  21. {
  22. String langPref = "Language";
  23. SharedPreferences prefs = getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
  24. String language = prefs.getString(langPref, "");
  25. changeLang(language);
  26. }
  27. public void saveLocale(String lang)
  28. {
  29. String langPref = "Language";
  30. SharedPreferences prefs = getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
  31. SharedPreferences.Editor editor = prefs.edit();
  32. editor.putString(langPref, lang);
  33. editor.commit();
  34. }
  35. public void changeLang(String lang)
  36. {
  37. if (lang.equalsIgnoreCase(""))
  38. return;
  39. myLocale = new Locale(lang);
  40. saveLocale(lang);
  41. Locale.setDefault(myLocale);
  42. android.content.res.Configuration config = new android.content.res.Configuration();
  43. config.locale = myLocale;
  44. getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
  45. updateTexts();
  46. }
  47. private void updateTexts()
  48. {
  49. txt_hello.setText(R.string.hello_world);
  50. btn_en.setText(R.string.btn_en);
  51. btn_ru.setText(R.string.btn_ru);
  52. btn_fr.setText(R.string.btn_fr);
  53. btn_de.setText(R.string.btn_de);
  54. }
  55. @Override
  56. public void onClick(View v) {
  57. String lang = "en";
  58. switch (v.getId()) {
  59. case R.id.btn_en:
  60. lang = "en";
  61. break;
  62. case R.id.btn_ru:
  63. lang = "ru";
  64. break;
  65. case R.id.btn_de:
  66. lang = "de";
  67. break;
  68. case R.id.btn_fr:
  69. lang = "fr";
  70. break;
  71. default:
  72. break;
  73. }
  74. changeLang(lang);
  75. }
  76. @Override
  77. public void onConfigurationChanged(android.content.res.Configuration newConfig) {
  78. super.onConfigurationChanged(newConfig);
  79. if (myLocale != null){
  80. newConfig.locale = myLocale;
  81. Locale.setDefault(myLocale);
  82. getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
  83. }
  84. }
  85. }





this is simple code for language change programaticaly. u can change multiple language .


- Mahesh Kailash Saraswat

Friday, 21 October 2016

Store your own app on Google Play Store


Store Your own App On Google Play Store


How to put your app in Play Store

if you're creating an application that you want to distribute to public , the best way to do so is to upload you application to GooglePlay . Google has help specifically aimed at developers. its great ref. Google play for Developers Help . There is also a very useful document entitled: Publish CheakList for Google Play . that discusses what is requered  to publist Google Play.

For in depth walk though of Google Play. Please read Publishing 

Register For Google Play.


The first step in publishing is to register for Goole Play . at the Google Play Publisher . The Process is relatively straightforword and should only take you a few minutes. 

Note : There is 25$ (1500 rs) charge to register. 

Are You Going to Sell Your App ?

if you want to sell app, instance of offering them for free with adsyou also need set up a Google Wallet Merchant account as described in the Getting starte with publishing



Uplode an App

After you've signed up for a Google Play Developer account , you can upload apps to Google Play Developer Console.


Add an Apk

  1. Go to your Google Play Developer Console
  2. Select All Application > Add new Application.
  3. Using the drop down menu , select a default language and add title fot your app as you wqant it to appear in Goole Play.
  4. Select Upload Apk.
  5. Chose the production , Beta,ot Alpha channels and Upload you Apk . For more info. on alpha/beta testing , go to use alpha/beta testing & staged rollouts .

Manage APK files 

package names for app files are unique and permanent so pleasename them carefully . package name cant be deleted or reused in future.












Next Step





- Mahesh Kailash Saraswat

Wednesday, 19 October 2016

Android MVC , MVP , MVVM


    MVC , MVP , MVVM 



   In this blog i am disscussing about Model View Controller (MVC), Model View Presenter (MVP) and Model View-View Model



Model View Controller (MVC) 


                           MVC design pattern splits an application into 3 part : Model , View , Controler























View :
              Component  dairectly intracy with user and is responsible for how user going to see our application, In MVC , Xml treated as view.

Model :  
               Model is the data source for application and main bussiness logic is defined here. It contail data objects that are used in application and is show to user . data sorce can be web , local bussiness (Sqlite) etc.                

Controller :
              Controller is responsible to process incoming request. It receives input from users vie the View, Then proces the User data with the help of Model and passing the result  back to view . Typically , it act as the coordinator between view and model.


Model View Presenter

This is similer to MVC pattern in which controller has been replaced by presenter. 


Model :
              The Model represent a set of classes that describes the business logic and data. also define business rules for data means how the datacan be changed and manipulated.

View :
          The view represent the ui componunts. its only responcible for displaying data that is received from the presenter as the result this also transforms the model(s) into UI.

Presenter :
            The presenter is responsible for handling all UI events on behalf of the view. This receive input from user vie View, then process the User data with the help of model and passing the results back to the View. Unlike View and Controler and presenter are completly decoupled from each other's and communicate to each other's by an a interface.

Also, preseter does not manage the incoming request traffic as controller.


Key Point about MVP Pattern

  • User interface with View.
  • There is one to one relationship between View and Presenter means one View is mapped to only one Presenter.
  • View has a reference  to Presenter but View has nor reference to Model.
  • Provied Two way communication between View and Presenter.

Model View ViewModel

                           This pattern supports two-way data binding between view and View Model. This enables automatic propogation of changes , within the state of View . Typicaly, the View model uses the observe pattern to notify changes in the view model to model.


Model :
           As descuss above same info follow above.

View :
           As descuss above same info. follow above.

View Model :
           The ViewModel is responsible for exposing method, commands , and othe properties thats help to maintain the stage of view , manupulate the model as the result of action on the view, and trigger event in view itself.

Key point about MVVMPattern

  • User interact with View.
  • There is many-to-onr relationship between View and ViewModel means many View can be mapped to one ViewModel.
  • view has refrance to ViewModel but ViewModel no Information about view
  • Supports two-way data binding between View andViewModel.


ref. from 






-Mahesh Kailash Saraswat

            

              

Tuesday, 18 October 2016

Splash Screen code Android

This Blog for beginer. i am showing you simple code of splash screen

Inside the Anctivity OnCreate Method


//this is used for hide action bar

getSupportActionBar().hide();


//After that we are chaking sharedPrefrance for user is already loged in or not. if loged in then home activity open other wise login

SharedPreferences mCheak=getSharePreferences("CheakLogIn", Context.MODE_PRIVATE);
String Name=mCheak.getString("Name","");


//Handler is used for autometicaly after some second activity call

Handler h= new Handler();

Runnable r = new Runnable ()
{

    @override
    public void run()
       {

//here we cheak if name is null login page open else home page

           if(Name.equals(" "))
          {
                  Intent i= new Intent(getApplicationContext (), Activity_LogIn.class);
                    startActivity(i);
                    finish();

          }else

               {
                    Intent i=new Intent(getApplicationContext(),Activity_Home.Class);
                    startActivity(i)
                    finish();

             }
  
      }

};

h.postDelayed(r,3000);        // 3000 is mili second means 3 second





- Mahesh Saraswat

Wednesday, 7 September 2016

Multiple Mobile Screen Suppor in Android

Multiple mobile screen support in Android

This blog about the multiple mobile screen support like Mobile screen small,large,tab etc.


I am explaining hear some points -

1)set support Screen in Manifest file

< suppor-screen  android:smallScreen="true"
                            android:normalScreen="true"
                            android:largeScreen="true"
                           android:xlargeScreen="true"
                            android:anyDensity="true"
                           android:resizeble="true" />


2) provide various layouts for various screen density

Go to  "res" -> "values" -> "dimens.xml"

<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin"> 16dp </dimen>
<dimen name="txt">30dp</dimen>



copy same value folder n past on res folder with name
value-hdpi ,value-ldpi , value-mdpi , value-nodpi



chenge the size of dimens.xml file dimen name

change size to -

value-hdpi  =  30dp
value-ldpi  = 50dp
value-mdpi = 50dp



same for images we  change the size and also past i mages diffrent size

(Hope So its good information)



-mahesh saraswat