Thingse/app/src/main/java/com/daneshzaki/thingse/ViewSomething.java
//fill fields with selected thing's values
fill fields with selected thing's values
fill fields with selected thing ' s values
private void loadValues()
    {
		String giftLabel = "";
		String currencyLabel = "";
    	Log.i("ViewSomething", "Bundle is " + bundle);
		ActionBar actionBar = getActionBar();
		actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33B5E5")));
		actionBar.setTitle(bundle.getString("name"));
		actionBar.setHomeButtonEnabled(true);
		actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
		SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    	if(bundle.getString("price").trim().startsWith("Gift :"))
    	{
    		giftLabel = "Received on ";
			((TextView)findViewById( R.id.priceValue)).setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_gift,0,0,0);
		}
		else
		{
			giftLabel = "Purchased on ";
			currencyLabel = sharedPrefs.getString("currencyPref", "Rs.");
			((TextView)findViewById( R.id.priceValue)).setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_price,0,0,0);
		}
		((TextView)findViewById( R.id.priceValue)).setText((currencyLabel + bundle.getString("price")).trim());
    	((TextView)findViewById( R.id.datePurchValue)).setText(giftLabel + bundle.getString("purchaseDate"));
    	if(bundle.getString("description")!= null && bundle.getString("description").trim().length()>0)
    	{
    		((TextView)findViewById( R.id.descValue)).setText(bundle.getString("description"));
    	}
    	else
    	{
    		((TextView)findViewById( R.id.descValue)).setText("One of the many things that I have");
    	}
		Typeface typeface = Typeface.createFromAsset( getResources().getAssets(), "SourceSansPro-Regular.otf");
		((TextView)findViewById( R.id.datePurchValue)).setTypeface(typeface);
		((TextView)findViewById( R.id.priceValue)).setTypeface(typeface);
		((TextView)findViewById( R.id.descValue)).setTypeface(typeface);
		ImageView thingImage = ((ImageView)findViewById(R.id.thingImage));
		if(bundle.getString("picLocation")!= null && bundle.getString("picLocation").trim().length() > 0)
    	{
			BitmapFactory.Options options = new BitmapFactory.Options();
			options.inSampleSize = 4;
			options.inJustDecodeBounds = true;
			options.inDither = false;
			if (options.outWidth > 3000 || options.outHeight > 2000)
			{
				options.inSampleSize = 6;
			} else if (options.outWidth > 2000 || options.outHeight > 1500)
			{
				options.inSampleSize = 5;
			} else if (options.outWidth > 1000 || options.outHeight > 1000)
			{
				options.inSampleSize = 3;
			}
			options.inJustDecodeBounds = false;
			Bitmap bmp = BitmapFactory.decodeFile(bundle.getString("picLocation"), options);
			Display display = getWindowManager().getDefaultDisplay();
			Point size = new Point();
			display.getSize(size);
			int width = size.x;
			int height = size.y;
			Log.i("ViewSomething", "***display width="+width);
			Log.i("ViewSomething", "***display height="+height);
			Log.i("ViewSomething", "***bmp width="+bmp.getWidth());
			Log.i("ViewSomething", "***bmp height="+bmp.getHeight());
			int ratio = bmp.getWidth() / bmp.getHeight();
			if (ratio <=0)
			{
				ratio = 1;
			}
			bmp = Bitmap.createScaledBitmap(bmp,
					(int) (height * ratio* 0.5), (int)(height *0.5), false);
			Drawable d = new BitmapDrawable(getResources(), bmp);
			thingImage.setImageDrawable(d);
			thingImage.setBackgroundColor(Color.LTGRAY);
    	}
    	else
    	{
			thingImage.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.1f));
			thingImage.setImageResource(R.drawable.ic_launcher);
			thingImage.setBackgroundColor(Color.LTGRAY);
    	}
    }
private void loadValues ( ) { String giftLabel = "" ; String currencyLabel = "" ; Log . i ( "ViewSomething" , "Bundle is " + bundle ) ; ActionBar actionBar = getActionBar ( ) ; actionBar . setBackgroundDrawable ( new ColorDrawable ( Color . parseColor ( "#33B5E5" ) ) ) ; actionBar . setTitle ( bundle . getString ( "name" ) ) ; actionBar . setHomeButtonEnabled ( true ) ; actionBar . setDisplayOptions ( ActionBar . DISPLAY_HOME_AS_UP | ActionBar . DISPLAY_SHOW_TITLE ) ; SharedPreferences sharedPrefs = PreferenceManager . getDefaultSharedPreferences ( this ) ; if ( bundle . getString ( "price" ) . trim ( ) . startsWith ( "Gift :" ) ) { giftLabel = "Received on " ; ( ( TextView ) findViewById ( R . id . priceValue ) ) . setCompoundDrawablesRelativeWithIntrinsicBounds ( R . drawable . ic_gift , 0 , 0 , 0 ) ; } else { giftLabel = "Purchased on " ; currencyLabel = sharedPrefs . getString ( "currencyPref" , "Rs." ) ; ( ( TextView ) findViewById ( R . id . priceValue ) ) . setCompoundDrawablesRelativeWithIntrinsicBounds ( R . drawable . ic_price , 0 , 0 , 0 ) ; } ( ( TextView ) findViewById ( R . id . priceValue ) ) . setText ( ( currencyLabel + bundle . getString ( "price" ) ) . trim ( ) ) ; ( ( TextView ) findViewById ( R . id . datePurchValue ) ) . setText ( giftLabel + bundle . getString ( "purchaseDate" ) ) ; if ( bundle . getString ( "description" ) != null && bundle . getString ( "description" ) . trim ( ) . length ( ) > 0 ) { ( ( TextView ) findViewById ( R . id . descValue ) ) . setText ( bundle . getString ( "description" ) ) ; } else { ( ( TextView ) findViewById ( R . id . descValue ) ) . setText ( "One of the many things that I have" ) ; } Typeface typeface = Typeface . createFromAsset ( getResources ( ) . getAssets ( ) , "SourceSansPro-Regular.otf" ) ; ( ( TextView ) findViewById ( R . id . datePurchValue ) ) . setTypeface ( typeface ) ; ( ( TextView ) findViewById ( R . id . priceValue ) ) . setTypeface ( typeface ) ; ( ( TextView ) findViewById ( R . id . descValue ) ) . setTypeface ( typeface ) ; ImageView thingImage = ( ( ImageView ) findViewById ( R . id . thingImage ) ) ; if ( bundle . getString ( "picLocation" ) != null && bundle . getString ( "picLocation" ) . trim ( ) . length ( ) > 0 ) { BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inSampleSize = 4 ; options . inJustDecodeBounds = true ; options . inDither = false ; if ( options . outWidth > 3000 || options . outHeight > 2000 ) { options . inSampleSize = 6 ; } else if ( options . outWidth > 2000 || options . outHeight > 1500 ) { options . inSampleSize = 5 ; } else if ( options . outWidth > 1000 || options . outHeight > 1000 ) { options . inSampleSize = 3 ; } options . inJustDecodeBounds = false ; Bitmap bmp = BitmapFactory . decodeFile ( bundle . getString ( "picLocation" ) , options ) ; Display display = getWindowManager ( ) . getDefaultDisplay ( ) ; Point size = new Point ( ) ; display . getSize ( size ) ; int width = size . x ; int height = size . y ; Log . i ( "ViewSomething" , "***display width=" + width ) ; Log . i ( "ViewSomething" , "***display height=" + height ) ; Log . i ( "ViewSomething" , "***bmp width=" + bmp . getWidth ( ) ) ; Log . i ( "ViewSomething" , "***bmp height=" + bmp . getHeight ( ) ) ; int ratio = bmp . getWidth ( ) / bmp . getHeight ( ) ; if ( ratio <= 0 ) { ratio = 1 ; } bmp = Bitmap . createScaledBitmap ( bmp , ( int ) ( height * ratio * 0.5 ) , ( int ) ( height * 0.5 ) , false ) ; Drawable d = new BitmapDrawable ( getResources ( ) , bmp ) ; thingImage . setImageDrawable ( d ) ; thingImage . setBackgroundColor ( Color . LTGRAY ) ; } else { thingImage . setLayoutParams ( new LinearLayout . LayoutParams ( LinearLayout . LayoutParams . WRAP_CONTENT , LinearLayout . LayoutParams . WRAP_CONTENT , 0.1f ) ) ; thingImage . setImageResource ( R . drawable . ic_launcher ) ; thingImage . setBackgroundColor ( Color . LTGRAY ) ; } }
fill fields with selected thing's values
fill fields with selected thing ' s values
//gift label //currency label //set thing name    //set label for gift //set currency chosen by user //set price //set purchase date //set description //set fonts for all text //scale and set pic //9-Sep-2015 scale large images //get display size //9-Sep-2015 scale large images //handle wide images //set default image if there is no associated pic with this thing