Android Open Source - UnitConverterUltimate-Studio Set Separator Dialog Fragment






From Project

Back to project page UnitConverterUltimate-Studio.

License

The source code is released under:

GNU General Public License

If you think the Android project UnitConverterUltimate-Studio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.physphil.android.unitconverterultimate.ui;
//from   w  w w  . j ava2s .c  om
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

import com.physphil.android.unitconverterultimate.R;
import com.physphil.android.unitconverterultimate.util.Constants;
import com.physphil.android.unitconverterultimate.util.Conversions;
import com.physphil.android.unitconverterultimate.util.Convert;



public class SetSeparatorDialogFragment extends DialogFragment{
  boolean separatorUsed = false;
  int currentSeparator = 0;
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.dialogSetSeparator);
    
    //Read from preferences file to determine current separator setting
    SharedPreferences preferences = activity.getPreferences(Context.MODE_PRIVATE);
    separatorUsed = preferences.getBoolean(Constants.SETTINGS_IS_SEPARATOR_USED, false);
    currentSeparator = preferences.getInt(Constants.SETTINGS_CURRENT_SEPARATOR, 0);
    
    builder.setSingleChoiceItems(R.array.separatorType, currentSeparator, new DialogInterface.OnClickListener() {      
      @Override
      public void onClick(DialogInterface dialog, int which) {
        currentSeparator = which;
        if(which==0){
          separatorUsed = false;
        }
        else{
          separatorUsed = true;
        }
        
      }
    });
    
    //Set the action buttons
    builder.setPositiveButton(R.string.buttonOK, new DialogInterface.OnClickListener() {      
      @Override
      public void onClick(DialogInterface dialog, int id) {
        // Store separator in preferences file
        SharedPreferences preferences = activity.getPreferences(Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(Constants.SETTINGS_IS_SEPARATOR_USED, separatorUsed);
        editor.putInt(Constants.SETTINGS_CURRENT_SEPARATOR, currentSeparator);
        editor.commit();
      }
    });
    
    builder.setNegativeButton(R.string.buttonCancel, new DialogInterface.OnClickListener() {      
      @Override
      public void onClick(DialogInterface dialog, int id) {
        //Exit back to main program
        dialog.cancel();
      }
    });
    
    return builder.create();
  }
  
  @Override
  public void onStop(){
    super.onStop();
    
//    //Read selected conversion info to call Convert
    int selectedConversion = getArguments().getInt(Constants.SETTINGS_CONVERSION, -1);
    int fromGroupId = getArguments().getInt(Constants.FROM_GROUP_ID, 0);
    int toGroupId = getArguments().getInt(Constants.TO_GROUP_ID, 0);
    
    //Call convert with new separator
    if(fromGroupId != 0 && toGroupId != 0 && selectedConversion != -1){
      
      if(selectedConversion == Conversions.TEMPERATURE){
        Convert.convertTempValue(getActivity());
      }
      else{
        Convert.convertValue(getActivity(), fromGroupId, toGroupId);
      }
    }
  }
}




Java Source Code List

com.physphil.android.unitconverterultimate.DonateActivity.java
com.physphil.android.unitconverterultimate.DonateFragment.java
com.physphil.android.unitconverterultimate.MainActivity.java
com.physphil.android.unitconverterultimate.iab.Base64DecoderException.java
com.physphil.android.unitconverterultimate.iab.Base64.java
com.physphil.android.unitconverterultimate.iab.IabException.java
com.physphil.android.unitconverterultimate.iab.IabHelper.java
com.physphil.android.unitconverterultimate.iab.IabResult.java
com.physphil.android.unitconverterultimate.iab.Inventory.java
com.physphil.android.unitconverterultimate.iab.Purchase.java
com.physphil.android.unitconverterultimate.iab.Security.java
com.physphil.android.unitconverterultimate.iab.SkuDetails.java
com.physphil.android.unitconverterultimate.ui.ConversionFragment.java
com.physphil.android.unitconverterultimate.ui.ConverterPagerAdapter.java
com.physphil.android.unitconverterultimate.ui.DonationListAdapter.java
com.physphil.android.unitconverterultimate.ui.SetDecimalSeparatorDialogFragment.java
com.physphil.android.unitconverterultimate.ui.SetDecimalsDialogFragment.java
com.physphil.android.unitconverterultimate.ui.SetSeparatorDialogFragment.java
com.physphil.android.unitconverterultimate.util.ChangeUnitListener.java
com.physphil.android.unitconverterultimate.util.Constants.java
com.physphil.android.unitconverterultimate.util.Conversions.java
com.physphil.android.unitconverterultimate.util.Convert.java
com.physphil.android.unitconverterultimate.util.Globals.java
com.physphil.android.unitconverterultimate.util.Util.java