구글 클라우드 프린트를 이용해서 웹에 있는 파일(pdf) 인쇄하기

 전체 소스 : GoogleCloudPrintExample.zip




Android Integration
https://developers.google.com/cloud-print/docs/android

Posted by incree

2016/09/17 22:34 2016/09/17 22:34
,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/369

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

Custom ListView로 AlertDialog 띄우기


사용자 삽입 이미지

사용자 삽입 이미지

사용자 삽입 이미지


AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.incree.customalertdialog">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.NoTitleBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

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

</manifest>


MainActivity.java
package com.incree.customalertdialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {

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

public void btnOpenPopupClickHandler(View view) {
final List<Product> items = new ArrayList<Product>();
items.add(new Product(1, "와퍼세트", "와퍼 단품+프렌치프라이R+콜라R", 8000, R.drawable.product_1));
items.add(new Product(2, "너겟킹10조각", "담백한 닭가슴살로 만든 바삭한 너켓킹", 5100, R.drawable.product_2));
items.add(new Product(3, "머쉬룸스테이크버거세트", "머쉬룸스테이크버거 단품+프렌치프라이R+콜라R", 9600, R.drawable.product_3));
items.add(new Product(4, "트리오팩", "통새우와퍼+와퍼+와퍼주니어+프렌치프라이(R)+치즈프라이+너겟킹4조각+어니언링+콜라(R)3", 24500, R.drawable.product_4));
items.add(new Product(5, "롱킹", "쇠고기 (호주산과 뉴질랜드산 섞음)", 6100, R.drawable.product_5));
final ProductListAdapter adapter = new ProductListAdapter(MainActivity.this, items);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
.setAdapter(adapter, null)
.setTitle("상품선택")
.setPositiveButton("선택구매", new DialogInterface.OnClickListener() { // 버튼은 테마에 따라서 모양이 다르게 모임
public void onClick(DialogInterface dialog, int whichButton) {
for(Product product : items) {
if (product.isSelected()) {
Log.d("MainActivity", product.getProductTitle() + " 선택");
}
}
}
})
.setNegativeButton("취소", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d("MainActivity", "취소 터치");
}
});

AlertDialog alertDialog = builder.create();
final ListView listView = alertDialog.getListView();
listView.setAdapter(adapter);
//listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // 여러 상품 선택을 위해 - 이 형태에서는 필요 없다
listView.setDivider(new ColorDrawable(Color.LTGRAY));
listView.setDividerHeight(1);
listView.setFocusable(false); // false를 해줘야 row touch event 가능
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CheckBox cbGoLargeChecked = (CheckBox)view.findViewById(R.id.productChecked);
Product tmpVo = items.get(position);
tmpVo.setSelected(!tmpVo.isSelected());
cbGoLargeChecked.setChecked(tmpVo.isSelected());
}
});

alertDialog.show();
}
}


class ProductListAdapter extends BaseAdapter
{
private Activity activity;
private List<Product> dataList;

public ProductListAdapter(Activity activity, List<Product> dataList) {
this.activity = activity;
this.dataList = dataList;
}

@Override
public int getCount()
{
return dataList.size();
}

@Override
public Object getItem(int position)
{
return dataList.get(position);
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if(view == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.product_dialog_list_row, null);
}

final Product data = dataList.get(position);

ImageView ivProductImage = (ImageView)view.findViewById(R.id.productImage);
final CheckBox cbProductChecked = (CheckBox)view.findViewById(R.id.productChecked);
TextView tvProductTitle = (TextView)view.findViewById(R.id.productTitle);
TextView tvProductDesc = (TextView)view.findViewById(R.id.productDesc);

cbProductChecked.setFocusable(false); // false를 해줘야 row touch event 가능

cbProductChecked.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
data.setSelected(cbProductChecked.isChecked());
}
});

ivProductImage.setImageDrawable(activity.getResources().getDrawable(data.getProductImageResource()));
tvProductTitle.setText(data.getProductTitle());
tvProductDesc.setText(data.getProductDesc());
cbProductChecked.setText(data.getProductPrice() + "원");
cbProductChecked.setChecked(data.isSelected());

return view;
}
}


activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.incree.customalertdialog.MainActivity">

<Button
android:id="@+id/btnOpenPopup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="btnOpenPopupClickHandler"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="상품 팝업 열기"/>
</RelativeLayout>





product_dialog_list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/productImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_centerVertical="true"/>

<TextView
android:id="@+id/productTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/productImage"
android:layout_alignParentTop="true"
android:hint="상품명"
android:textColor="#252525"
android:textSize="16sp"
android:textStyle="bold"/>

<CheckBox
android:id="@+id/productChecked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layoutDirection="rtl"
android:textColor="#252525"
/>

<TextView
android:id="@+id/productDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_toRightOf="@id/productImage"
android:layout_toLeftOf="@id/productChecked"
android:layout_below="@id/productTitle"
android:hint="상품 설명"
android:textColor="#252525"
android:textSize="12sp"/>
</RelativeLayout>

 전체 소스 : CustomAlertDialog.zip


Posted by incree

2016/09/10 09:08 2016/09/10 09:08
, ,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/368

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다


Notices

Archives

Authors

  1. incree

Recent Trackbacks

Calendar

«   2016/09   »
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

Site Stats

Total hits:
427668
Today:
68
Yesterday:
210