android - Share Intent: customize layout -
is there way can customize layout of share intent? default listview, if client wants same, show grid view! know how filter required apps using packagemanager. want change listview gridview else same.
call below dialog per requirement:
private void showalertdialog() { packagemanager pm = getpackagemanager(); alertdialog.builder builder = new alertdialog.builder(this); gridview gridview = new gridview(this); email.putextra(intent.extra_email, new string[] { "velmurugan@androidtoppers.com" }); email.putextra(intent.extra_subject, "hi"); email.putextra(intent.extra_text, "hi,this test"); email.settype("text/plain"); list<resolveinfo> launchables = pm.queryintentactivities(email, 0); collections .sort(launchables, new resolveinfo.displaynamecomparator(pm)); adapter = new appadapter(pm, launchables); gridview.setnumcolumns(3); gridview.setadapter(adapter); gridview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int position, long arg3) { // todo auto-generated method stub resolveinfo launchable = adapter.getitem(position); activityinfo activity = launchable.activityinfo; componentname name = new componentname( activity.applicationinfo.packagename, activity.name); email.addcategory(intent.category_launcher); email.setflags(intent.flag_activity_new_task | intent.flag_activity_reset_task_if_needed); email.setcomponent(name); startactivity(email); } }); builder.setview(gridview); builder.settitle("share"); builder.show(); }
row.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:orientation="vertical" android:padding="5dp" > <imageview android:id="@+id/icon" android:layout_width="60dp" android:layout_height="60dp" android:paddingbottom="2dp" android:paddingleft="2dp" android:paddingright="5dp" android:paddingtop="2dp" /> <textview android:id="@+id/label" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_torightof="@id/icon" android:gravity="center_vertical" android:paddingbottom="2sp" android:paddingtop="4sp" android:textcolor="@android:color/white" android:textsize="11pt" /> </linearlayout>
adapter class:
class appadapter extends arrayadapter<resolveinfo> { private packagemanager pm = null; appadapter(context context, packagemanager pm, list<resolveinfo> apps) { super(context, r.layout.row, apps); this.pm = pm; } @override public view getview(int position, view convertview, viewgroup parent) { if (convertview == null) { convertview = newview(parent); } bindview(position, convertview); return (convertview); } private view newview(viewgroup parent) { return (getlayoutinflater().inflate(r.layout.row, parent, false)); } private void bindview(int position, view row) { textview label = (textview) row.findviewbyid(r.id.label); label.settext(getitem(position).loadlabel(pm)); imageview icon = (imageview) row.findviewbyid(r.id.icon); icon.setimagedrawable(getitem(position).loadicon(pm)); } }
Comments
Post a Comment