View Single Post
  #77  
Old November 15th 18, 07:02 AM posted to comp.mobile.android,alt.comp.freeware,microsoft.public.windowsxp.general
arlen michael holder
external usenet poster
 
Posts: 48
Default Report: My first "hello world" using Android Studio freeware on Windows worked just fine (in about an hour)

On Thu, 15 Nov 2018 05:56:55 -0000 (UTC), arlen michael holder wrote:

These are real items, at my local grocery store, where I took
pictures of what I normally buy there (i.e., the best deals).


Hi Bill,
Here's what the "custom" shopping list looks like on the phone:
http://www.bild.me/bild.php?file=5881250androidstudio73.jpg

The original design is pretty good because everything is just an
item in a list, which can be of any length.

Hence, the only files that changed to create that shopping list were
C:\tmp\android\app08\app\src\main\res\values\strin gs.xml
C:\tmp\android\app08\app\src\main\java\com\kiss\ap p08\DetailActivity.java

Where these are the files:
================================================== ==========================
I added the items to the "strings.xml" file:
C:\tmp\android\app08\app\src\main\res\values\strin gs.xml

resources
string name="app_name"app08/string

string-array name="items"
itemchocolate/item
itemeggs/item
itemmilk/item
itemorange juice/item
itempasta/item
itempineapple juice/item
itemtable wine/item
itembread wrap/item
/string-array

string-array name="prices"
item$4.99/item
item$1.69/item
item$2.99/item
item$2.99/item
item$0.99/item
item$3.99/item
item$5.99/item
item$3.29/item
/string-array

string-array name="descriptions"
itemchocolate bar (no preservatives)/item
itemdozen eggs (free roaming)/item
itemgallon of milk (happy cows)/item
item1/2 gallon of oj (fresh)/item
itempound of pasta (semolina wheat)/item
itemhalf gallon of pineapple juice (fresh)/item
itemtable wine (California)/item
itembread wrap (wheat)/item
/string-array
/resources
================================================== ==========================
And I added the switches to the DetailActivity.java file:
C:\tmp\android\app08\app\src\main\java\com\kiss\ap p08\DetailActivity.java

package com.kiss.app08;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Display;
import android.widget.ImageView;

public class DetailActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);

Intent in = getIntent();
int index = in.getIntExtra("com.kiss.app08.ITEM_INDEX", -1);

if (index -1) {
int pic = getImg(index);
ImageView img = (ImageView) findViewById(R.id.imageView);
scaleImg(img, pic);
}

}

private int getImg(int index) {
switch (index) {
case 0: return R.drawable.chocolate;
case 1: return R.drawable.egg;
case 2: return R.drawable.milk;
case 3: return R.drawable.oj;
case 4: return R.drawable.pasta;
case 5: return R.drawable.pj;
case 6: return R.drawable.vino;
case 7: return R.drawable.wrap;
default: return -1;
}
}

private void scaleImg(ImageView img, int pic) {
Display screen = getWindowManager().getDefaultDisplay();
BitmapFactory .Options options = new BitmapFactory.Options();

options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), pic, options);

int imgWidth = options.outWidth;
int screenWidth = screen.getWidth();

if (imgWidth screenWidth) {
int ratio = Math.round( (float) imgWidth / (float)screenWidth);
options.inSampleSize = ratio;
}

options.inJustDecodeBounds = false;
Bitmap scaledImg = BitmapFactory.decodeResource(getResources(),
pic, options);
img.setImageBitmap(scaledImg);
}
}
================================================== ==========================
The rest of the files were untouched from what they were in app06.
C:\tmp\android\app08\app\src\main\java\com\kiss\ap p08\MainActivity.java

package com.kiss.app08;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {

ListView myListView;
String[] items;
String[] prices;
String[] descriptions;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Resources res = getResources();
myListView = (ListView) findViewById(R.id.myListView);
items = res.getStringArray(R.array.items);
prices = res.getStringArray(R.array.prices);
descriptions = res.getStringArray(R.array.descriptions);

ItemAdapter itemAdapter = new ItemAdapter(this, items, prices,
descriptions);
myListView.setAdapter(itemAdapter);

myListView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView? parent, View view, int
i, long l) {
Intent showDetailActivity = new
Intent(getApplicationContext(), DetailActivity.class);
showDetailActivity.putExtra("com.kiss.app08.ITEM_I NDEX",
i);
startActivity(showDetailActivity);
}
});


}
}
================================================== ==========================
C:\tmp\android\app08\app\src\main\java\com\kiss\ap p08\ItemAdapter.java

package com.kiss.app08;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ItemAdapter extends BaseAdapter {

LayoutInflater mInflator;
String[] items;
String[] prices;
String[] descriptions;

public ItemAdapter(Context c, String[] i, String[] p, String[] d) {
items = i;
prices = p;
descriptions = d;
mInflator = (LayoutInflater)
c.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
}

@Override
public int getCount() {
return items.length;
}

@Override
public Object getItem(int i) {
return items[i];
}

@Override
public long getItemId(int i) {
return i;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {

View v = mInflator.inflate(R.layout.my_listview_detail, null);
TextView nameTextView = (TextView)
v.findViewById(R.id.nameTextView);
TextView descriptionTextView = (TextView)
v.findViewById(R.id.descriptionTextView);
TextView priceTextView = (TextView)
v.findViewById(R.id.priceTextView);

String name = items[i];
String desc = descriptions[i];
String cost = prices[i];

nameTextView.setText(name);
descriptionTextView.setText(desc);
priceTextView.setText(cost);

return v;
}
}
================================================== ==========================
C:\tmp\android\app08\app\src\main\AndroidManifest. xml

?xml version="1.0" encoding="utf-8"?
manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kiss.app08"

application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
activity android:name=".MainActivity"
intent-filter
action android:name="android.intent.action.MAIN" /

category android:name="android.intent.category.LAUNCHER"
/
/intent-filter
/activity
activity android:name=".DetailActivity"/activity
/application

/manifest
================================================== ==========================
Ads