private void listAll() { ViewGroup root = mList; root.removeAllViews(); // 列出所有已经安装的插件 Collection<PluginDescriptor> plugins = PluginLoader.getPlugins(); Iterator<PluginDescriptor> itr = plugins.iterator(); while (itr.hasNext()) { final PluginDescriptor pluginDescriptor = itr.next(); Button button = new Button(this); button.setPadding(10, 10, 10, 10); button.setText("插件id:" + pluginDescriptor.getPackageName() + ",点击查看"); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(PluginListActivity.this, PluginDetailActivity.class); intent.putExtra("plugin_id", pluginDescriptor.getPackageName()); startActivity(intent); } }); LayoutParams layoutParam = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); layoutParam.topMargin = 10; layoutParam.bottomMargin = 10; layoutParam.gravity = Gravity.LEFT; root.addView(button, layoutParam); } }
public PRTHeader(Context context) { super(context); setOrientation(VERTICAL); LinearLayout llInner = new LinearLayout(context); LinearLayout.LayoutParams lpInner = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpInner.gravity = Gravity.CENTER_HORIZONTAL; addView(llInner, lpInner); ivArrow = new RotateImageView(context); int resId = getBitmapRes(context, "ssdk_oks_ptr_ptr"); if (resId > 0) { ivArrow.setImageResource(resId); } int dp_32 = dipToPx(context, 32); LayoutParams lpIv = new LayoutParams(dp_32, dp_32); lpIv.gravity = Gravity.CENTER_VERTICAL; llInner.addView(ivArrow, lpIv); pbRefreshing = new ProgressBar(context); llInner.addView(pbRefreshing, lpIv); pbRefreshing.setVisibility(View.GONE); tvHeader = new TextView(getContext()); tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvHeader.setGravity(Gravity.CENTER); int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10); tvHeader.setPadding(dp_10, dp_10, dp_10, dp_10); tvHeader.setTextColor(0xff000000); LayoutParams lpTv = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpTv.gravity = Gravity.CENTER_VERTICAL; llInner.addView(tvHeader, lpTv); }
// if platform selected form platform gridview is SinaWeibo, // TencentWeibo, Facebook, or Twitter, there will be a button // in the left-bottom of the page, which provides At-friends function private LinearLayout getAtLine(String platform) { if (!isShowAtUserLayout(platform)) { return null; } LinearLayout llAt = new LinearLayout(getContext()); LayoutParams lpAt = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpAt.rightMargin = dipToPx(getContext(), 4); lpAt.gravity = Gravity.LEFT | Gravity.BOTTOM; lpAt.weight = 1; llAt.setLayoutParams(lpAt); llAt.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (platforms != null && platforms.size() > 0) { FollowListPage subPage = new FollowListPage(); subPage.setPlatform(platforms.get(0)); subPage.showForResult(activity, null, EditPage.this); } else { int resId = getStringRes(activity, "ssdk_oks_select_one_plat_at_least"); if (resId > 0) { Toast.makeText(getContext(), resId, Toast.LENGTH_SHORT).show(); } } } }); TextView tvAt = new TextView(getContext()); int resId = getBitmapRes(activity, "ssdk_oks_btn_back_nor"); if (resId > 0) { tvAt.setBackgroundResource(resId); } int dp_32 = dipToPx(getContext(), 32); tvAt.setLayoutParams(new LayoutParams(dp_32, dp_32)); tvAt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvAt.setText(getAtUserButtonText(platform)); int dp_2 = dipToPx(getContext(), 2); tvAt.setPadding(0, 0, 0, dp_2); tvAt.setTypeface(Typeface.DEFAULT_BOLD); tvAt.setTextColor(0xff000000); tvAt.setGravity(Gravity.CENTER); llAt.addView(tvAt); TextView tvName = new TextView(getContext()); tvName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvName.setTextColor(0xff000000); resId = getStringRes(activity, "ssdk_oks_list_friends"); String text = getContext().getString(resId, getName(platform)); tvName.setText(text); LayoutParams lpName = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpName.gravity = Gravity.CENTER_VERTICAL; tvName.setLayoutParams(lpName); llAt.addView(tvName); return llAt; }
// platform logos private LinearLayout getPlatformList() { LinearLayout llToolBar = new LinearLayout(getContext()); LayoutParams lpTb = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llToolBar.setLayoutParams(lpTb); TextView tvShareTo = new TextView(getContext()); int resId = getStringRes(activity, "ssdk_oks_share_to"); if (resId > 0) { tvShareTo.setText(resId); } tvShareTo.setTextColor(0xffcfcfcf); tvShareTo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); int dp_9 = dipToPx(getContext(), 9); LayoutParams lpShareTo = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpShareTo.gravity = Gravity.CENTER_VERTICAL; lpShareTo.setMargins(dp_9, 0, 0, 0); tvShareTo.setLayoutParams(lpShareTo); llToolBar.addView(tvShareTo); HorizontalScrollView sv = new HorizontalScrollView(getContext()); sv.setHorizontalScrollBarEnabled(false); sv.setHorizontalFadingEdgeEnabled(false); LayoutParams lpSv = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpSv.setMargins(dp_9, dp_9, dp_9, dp_9); sv.setLayoutParams(lpSv); llToolBar.addView(sv); llPlat = new LinearLayout(getContext()); llPlat.setLayoutParams( new HorizontalScrollView.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); sv.addView(llPlat); return llToolBar; }
public static void addActionsButton(BaseButton baseButton) { Drawable iconImage = mShell.getResources().getDrawable(baseButton.getButtonIconId()); int ten_dip = (int) (10 * mShell.getResources().getDisplayMetrics().density); ImageView buttonIcon = new ImageView(mShell.getContext()); buttonIcon.setImageDrawable(iconImage); LayoutParams iconParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); iconParams.setMargins(ten_dip, 0, 0, 0); iconParams.gravity = Gravity.CENTER_VERTICAL; TextView buttonText = new TextView(mShell.getContext()); buttonText.setText(baseButton.getButtonText()); buttonText.setTextColor(Color.WHITE); buttonText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); LayoutParams textParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); buttonText.setPadding(ten_dip, ten_dip, ten_dip, ten_dip); LinearLayout button = new LinearLayout(mShell.getContext()); button.addView(buttonIcon, iconParams); button.addView(buttonText, textParams); baseButton.setActionImageView(buttonIcon); baseButton.setActionTextView(buttonText); button.setOnClickListener(baseButton.getOnClickListener()); ActionButtonRunnable addButtonRunnable = new ActionButtonRunnable(button); mCurrentActivity.runOnUiThread(addButtonRunnable); }
private void init() { // TODO Auto-generated method stub // 滑动对象, LastRefreshTime = Calendar.getInstance(); scroller = new Scroller(mContext); // 刷新视图顶端的的view,也就是下拉之后显示在的顶端的那部分布局 refreshView = LayoutInflater.from(mContext).inflate(R.layout.refresh_top_item, null); // 指示器view refreshIndicatorView = (ImageView) refreshView.findViewById(R.id.indicator); // 刷新bar bar = (ProgressBar) refreshView.findViewById(R.id.progress); // 下拉显示text downTextView = (TextView) refreshView.findViewById(R.id.refresh_hint); // 下来显示时间 timeTextView = (TextView) refreshView.findViewById(R.id.refresh_time); reFreshTimeLayout = (LinearLayout) refreshView.findViewById(R.id.refresh_time_layout); LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, -refreshTargetTop); lp.topMargin = refreshTargetTop; // 将刷新区域大小赋予布局参数的顶部margin lp.gravity = Gravity.CENTER; // 居中显示 addView(refreshView, lp); // 此部分布局是加载在生成参数1的上下文所在的布局中 downTextString = mContext.getResources().getString(R.string.refresh_down_text); releaseTextString = mContext.getResources().getString(R.string.refresh_release_text); }
public void setIndeterminate(boolean z) { if (this.mProgressBar.isIndeterminate() != z) { LayoutParams layoutParams = (LayoutParams) this.mProgressBar.getLayoutParams(); if (z) { layoutParams.width = -2; layoutParams.height = -2; layoutParams.gravity = 17; } else { layoutParams.width = -1; layoutParams.height = (int) TypedValue.applyDimension(1, 1.0f, getResources().getDisplayMetrics()); layoutParams.gravity = 48; } this.mProgressBar.setLayoutParams(layoutParams); this.mProgressBar.setIndeterminate(z); } }
@Override protected void refreshDisplayView() { fileDisplayList.removeAllViews(); for (final Metadata m : files) { View fileRow = inflater.inflate(R.layout.file_display_row, null); LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.RIGHT; setUpFileRow(m, fileRow, fileDisplayList, lp); } }
private LinearLayout createLinearLayout() { LinearLayout linearLayout = new LinearLayout(context); LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.gravity = Gravity.CENTER_VERTICAL; linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setPadding(0, height / 100, 0, height / 100); linearLayout.setBackgroundColor(Color.WHITE); linearLayout.setLayoutParams(layoutParams); return linearLayout; }
private void testCharButton(Context context, ViewGroup root) { WheelButton cb = new WheelButton(context); LayoutParams lp = new LayoutParams(300, 500); lp.gravity = Gravity.CENTER_HORIZONTAL; root.addView(cb, lp); WheelButtonItem chile; for (int i = 0; i < 6; i++) { chile = new WheelButtonItem(); chile.weight = (int) (Math.random() * 100); chile.backgroundColor = (int) (Math.random() * 0xffffff) + 0xff000000; chile.textColor = (0xffffffff - chile.backgroundColor) | 0xff000000; chile.text = "btn" + i; if (i < 3) { // cb.addCenterButton(chile); } else if (i == 1) { chile.backgroundColor = 0xffffffff; chile.clickAble = false; chile.visibility = false; chile.text = ""; } else cb.addCircleButton(chile); } cb.setmCenterUserWeightCount(100); chile = new WheelButtonItem(); chile.weight = (int) (Math.random() * 100); chile.backgroundColor = (int) (Math.random() * 0xffffff) + 0xff000000; chile.textColor = (0xffffffff - chile.backgroundColor) | 0xff000000; chile.text = "btn" + chile.weight; cb.addCenterButton(chile); // chile=new WheelButtonItem(); // chile.weight=90; // chile.backgroundColor=(int) (Math.random()*0xffffff)+0xff000000; // chile.textColor=(0xffffffff-chile.backgroundColor)|0xff000000; // chile.text="btn"+chile.weight; // chile.visibility=false; // cb.addCenterButton(chile); cb.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick( WheelButton parent, WheelButtonItem item, int position, int flag) { if (flag == WheelButton.ITEM_TYPE_CENTER) { Toast.makeText(parent.getContext(), item.text, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(parent.getContext(), item.text, Toast.LENGTH_SHORT).show(); } } }); }
private void testLineView(Context context, ViewGroup root) { // LinearLayout l=new LinearLayout(context); // this.setContentView(l); // create a LineView DividerLinearLayout cv = new DividerLinearLayout(context); cv.setOrientation(LinearLayout.VERTICAL); cv.setBackgroundColor(Color.BLUE); // add lineView to ContentView LayoutParams lp = new LayoutParams(300, LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.CENTER; root.addView(cv, lp); android.view.ViewGroup.LayoutParams chileLayoutLp = new LayoutParams( android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); for (int i = 0; i < 2; i++) { // add ChileView cv.addView( createItemView(context, chileLayoutLp, Gravity.CENTER, "Title" + i, "Content" + i)); } LinearLayout BottomLin = new LinearLayout(context); BottomLin.setGravity(Gravity.CENTER); BottomLin.setLayoutParams(chileLayoutLp); android.view.ViewGroup.LayoutParams chileLayoutLp2 = new LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); BottomLin.addView( createItemView(context, chileLayoutLp2, Gravity.CENTER, "Title L", "Content Left")); ImageView diviImg = new ImageView(context); diviImg.setScaleType(ScaleType.FIT_XY); diviImg.setImageResource(R.drawable.ic_launcher); android.widget.LinearLayout.LayoutParams dividerLp = new android.widget.LinearLayout.LayoutParams(4, LayoutParams.WRAP_CONTENT); BottomLin.addView(diviImg, dividerLp); BottomLin.addView( createItemView(context, chileLayoutLp2, Gravity.CENTER, "Title R", "Content Right")); cv.addView(BottomLin); Button sureBtn = new Button(context); sureBtn.setText("Detaile"); cv.addView(sureBtn); }
private RelativeLayout createImage(String path, int id, final String bigPath) { RelativeLayout relativeLayout = new RelativeLayout(context); LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); layoutParams.gravity = Gravity.CENTER; layoutParams.leftMargin = width / 55; layoutParams.weight = 1; relativeLayout.setLayoutParams(layoutParams); ImageView imageView = new ImageView(context); imageView.setId(id); imageView.setOnLongClickListener(this); imageView.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // 展示大图片 BigImageActivity.setViewData(bigPath); startActivity(new Intent(CaseTestActivity.this, BigImageActivity.class)); } }); LayoutParams imageViewParams = new LayoutParams(width / 15 * 4, width / 15 * 4); imageView.setLayoutParams(imageViewParams); imageView.setScaleType(ScaleType.CENTER_CROP); if (!"null".equals(path) && !"".equals(path)) { if (path.startsWith("http:")) { imageView.setTag(path); imageView.setImageResource(R.anim.loading_anim_test); ImageListener listener = ImageLoader.getImageListener(imageView, 0, android.R.drawable.ic_menu_delete); mImageLoader.get(path, listener, 200, 200); } else { Bitmap bitmap = CommonUtil.readBitMap(200, path); imageView.setImageBitmap(bitmap); } } relativeLayout.addView(imageView); return relativeLayout; }
private LinearLayout getBodyBottom() { LinearLayout llBottom = new LinearLayout(getContext()); llBottom.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); LinearLayout line = getAtLine(platforms.get(0).getName()); if (line != null) { llBottom.addView(line); } // Words counter tvCounter = new TextView(getContext()); tvCounter.setText(String.valueOf(MAX_TEXT_COUNT)); tvCounter.setTextColor(0xffcfcfcf); tvCounter.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvCounter.setTypeface(Typeface.DEFAULT_BOLD); LayoutParams lpCounter = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpCounter.gravity = Gravity.CENTER_VERTICAL; tvCounter.setLayoutParams(lpCounter); llBottom.addView(tvCounter); return llBottom; }
@Override public View getChildView( int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { final Entity ent = (Entity) getChild(groupPosition, childPosition); // Set an id depending on the table ent belongs to int entId; if (ent.getTable() == "homework") { entId = 1; } else if (ent.getTable() == "assignment") { entId = 2; } else if (ent.getTable() == "exam") { entId = 3; } else { entId = 4; } // Depending on the id, do something different. For the first three, the only bit that changes // is the string in the alertDialog and the activity // that's opened when you press the element on the list. I'll comment due homework list, the // other are the same. switch (entId) { // Due homework list case 1: convertView = View.inflate(AgendaDay.this, R.layout.agendaday_dueitem, null); try { Button title = (Button) convertView.findViewById(R.id.title); ImageView remove = (ImageView) convertView.findViewById(R.id.dueremove); TextView dueclass = (TextView) convertView.findViewById(R.id.dueclass); LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.linearLayout1); // When editing this element, get the date it was set, not the date you're viewing. final Calendar c = Calendar.getInstance(); c.setTimeInMillis(ent.getLong("setDate")); // Set text title.setText("- " + ent.getString("title")); // If the homework is done, strike it through. if (ent.getInt("done") == 1) { title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); layout.setBackgroundColor(getResources().getColor(R.color.grey)); } title.setOnClickListener( new OnClickListener() { // When the element's pressed, open AddHwDialog with all the necessary data to // edit it. public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddHwDialog.class); i.putExtra("homework_id", ent.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureHomework) .setTitle(R.string.sureHomeworkTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { // Remove the element. public void onClick(DialogInterface dialog, int arg1) { ent.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); // Get the subject this element is associated with... Entity classEnt = new Entity("class", ent.getLong("class_id")); Entity subject = new Entity("subject", classEnt.getLong("subject_id")); // ...to put it as the name that appears. dueclass.setText(subject.getString("title")); } catch (Exception e) { e.printStackTrace(); } break; // Due assignment list case 2: convertView = View.inflate(AgendaDay.this, R.layout.agendaday_dueitem, null); try { Button title = (Button) convertView.findViewById(R.id.title); ImageView remove = (ImageView) convertView.findViewById(R.id.dueremove); TextView dueclass = (TextView) convertView.findViewById(R.id.dueclass); LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.linearLayout1); final Calendar c = Calendar.getInstance(); c.setTimeInMillis(ent.getLong("setDate")); title.setText("- " + ent.getString("title")); if (ent.getInt("done") == 1) { title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); layout.setBackgroundColor(getResources().getColor(R.color.grey)); } title.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddAssignDialog.class); i.putExtra("assign_id", ent.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureAssignment) .setTitle(R.string.sureAssignmentTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); Entity classEnt = new Entity("class", ent.getLong("class_id")); Entity subject = new Entity("subject", classEnt.getLong("subject_id")); dueclass.setText(subject.getString("title")); } catch (Exception e) { e.printStackTrace(); } break; // Due exam list case 3: convertView = View.inflate(AgendaDay.this, R.layout.agendaday_dueitem, null); try { Button title = (Button) convertView.findViewById(R.id.title); ImageView remove = (ImageView) convertView.findViewById(R.id.dueremove); TextView dueclass = (TextView) convertView.findViewById(R.id.dueclass); final Calendar c = Calendar.getInstance(); c.setTimeInMillis(ent.getLong("setDate")); title.setText("- " + ent.getString("title")); title.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddExamDialog.class); i.putExtra("exam_id", ent.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureExam) .setTitle(R.string.sureExamTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); Entity classEnt = new Entity("class", ent.getLong("class_id")); Entity subject = new Entity("subject", classEnt.getLong("subject_id")); dueclass.setText(subject.getString("title")); } catch (Exception e) { e.printStackTrace(); } break; // Today's classes list case 4: convertView = View.inflate(AgendaDay.this, R.layout.agendaday_item, null); try { Long subjectid = (Long) ent.getValue("subject_id"); Entity subjectent = new Entity("subject", subjectid); // Get when the class starts and when it ends to... String starttimehour = ent.getString("starttimehour"); // Add a 0 if it's lower than 10, Java doesn't do it automatically. if (Integer.parseInt(starttimehour) < 10) { starttimehour = "0" + starttimehour; } String starttimeminute = ent.getString("starttimeminute"); if (Integer.parseInt(starttimeminute) < 10) { starttimeminute = "0" + starttimeminute; } String endtimehour = ent.getString("endtimehour"); if (Integer.parseInt(endtimehour) < 10) { endtimehour = "0" + endtimehour; } String endtimeminute = ent.getString("endtimeminute"); if (Integer.parseInt(endtimeminute) < 10) { endtimeminute = "0" + endtimeminute; } // ...display it nicely in a TextView String classLength = " (" + starttimehour + ":" + starttimeminute + "-" + endtimehour + ":" + endtimeminute + ")"; TextView subject = (TextView) convertView.findViewById(R.id.subjectname); TextView classLengthText = (TextView) convertView.findViewById(R.id.classlength); subject.setText(subjectent.getString("title")); classLengthText.setText(classLength); LinearLayout hwlist = (LinearLayout) convertView.findViewById(R.id.homeworkLinearLayout); LinearLayout assignlist = (LinearLayout) convertView.findViewById(R.id.assignmentLinearLayout); LinearLayout examlist = (LinearLayout) convertView.findViewById(R.id.examLinearLayout); try { // Start my three arraylists. entHw = new ArrayList<Entity>(); entExams = new ArrayList<Entity>(); entAssignments = new ArrayList<Entity>(); // Get today's date. Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); c.set(mYear, mMonth, mDay, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); // Get all homework associated to the class you're viewing. List<Entity> entclassHw = db.getEntityList("homework", "class_id = '" + ent.getId() + "'"); Iterator<Entity> iter = entclassHw.iterator(); // Put in entHw only those that are set on the day you're viewing while (iter.hasNext()) { Entity HwEnt = (Entity) iter.next(); Calendar d = Calendar.getInstance(TimeZone.getTimeZone("GMT")); d.setTimeInMillis(HwEnt.getLong("setDate")); if (d.getTimeInMillis() == c.getTimeInMillis()) { entHw.add(HwEnt); } } List<Entity> entclassAssignments = db.getEntityList("assignment", "class_id = '" + ent.getId() + "'"); Iterator<Entity> iter2 = entclassAssignments.iterator(); while (iter2.hasNext()) { Entity AssignEnt = (Entity) iter2.next(); Calendar d = Calendar.getInstance(TimeZone.getTimeZone("GMT")); d.setTimeInMillis(AssignEnt.getLong("setDate")); if (d.get(Calendar.YEAR) == c.get(Calendar.YEAR) && d.get(Calendar.DAY_OF_YEAR) == c.get(Calendar.DAY_OF_YEAR)) { entAssignments.add(AssignEnt); } } List<Entity> entclassExams = db.getEntityList("exam", "class_id = '" + ent.getId() + "'"); Iterator<Entity> iter3 = entclassExams.iterator(); while (iter3.hasNext()) { Entity ExamEnt = (Entity) iter3.next(); Calendar d = Calendar.getInstance(TimeZone.getTimeZone("GMT")); d.setTimeInMillis(ExamEnt.getLong("setDate")); if (d.get(Calendar.YEAR) == c.get(Calendar.YEAR) && d.get(Calendar.DAY_OF_YEAR) == c.get(Calendar.DAY_OF_YEAR)) { entExams.add(ExamEnt); } } } catch (Exception e) { e.printStackTrace(); } // Get a date for the day you're viewing final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); c.set(mYear, mMonth, mDay, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); // For every homework you have on the day your viewing and the class element the list is // at. for (final Entity ent2 : entHw) { LinearLayout linear = new LinearLayout(getApplicationContext()); linear.setOrientation(LinearLayout.HORIZONTAL); LayoutParams linearLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); linear.setLayoutParams(linearLayoutParams); linear.setBackgroundResource(R.color.purple); Button hwTitle = new Button(getApplicationContext()); hwTitle.setText("- " + ent2.getString("title")); if (ent2.getInt("done") == 1) { hwTitle.setPaintFlags(hwTitle.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } hwTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 19); hwTitle.setGravity(Gravity.LEFT); hwTitle.setPadding(5, 5, 0, 5); LayoutParams titleButtonLayoutParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1); hwTitle.setLayoutParams(titleButtonLayoutParams); hwTitle.setBackgroundColor(android.R.color.transparent); hwTitle.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddHwDialog.class); i.putExtra("homework_id", ent2.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); ImageView remove = new ImageView(getApplicationContext()); LayoutParams removeButtonLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); removeButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL; remove.setBackgroundDrawable(getResources().getDrawable(R.drawable.remove)); remove.setLayoutParams(removeButtonLayoutParams); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureHomework) .setTitle(R.string.sureHomeworkTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent2.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); linear.addView(hwTitle); linear.addView(remove); hwlist.addView(linear); } for (final Entity ent2 : entAssignments) { LinearLayout linear = new LinearLayout(getApplicationContext()); linear.setOrientation(LinearLayout.HORIZONTAL); LayoutParams linearLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); linear.setLayoutParams(linearLayoutParams); linear.setBackgroundResource(R.color.light_green); Button assignTitle = new Button(getApplicationContext()); assignTitle.setText("- " + ent2.getString("title")); if (ent2.getInt("done") == 1) { assignTitle.setPaintFlags( assignTitle.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } assignTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); assignTitle.setGravity(Gravity.LEFT); assignTitle.setPadding(5, 5, 0, 5); LayoutParams titleButtonLayoutParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1); assignTitle.setLayoutParams(titleButtonLayoutParams); assignTitle.setBackgroundColor(android.R.color.transparent); assignTitle.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddAssignDialog.class); i.putExtra("assign_id", ent2.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); ImageView remove = new ImageView(getApplicationContext()); LayoutParams removeButtonLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); removeButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL; remove.setBackgroundDrawable(getResources().getDrawable(R.drawable.remove)); remove.setLayoutParams(removeButtonLayoutParams); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureAssignment) .setTitle(R.string.sureAssignmentTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent2.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); linear.addView(assignTitle); linear.addView(remove); assignlist.addView(linear); } for (final Entity ent2 : entExams) { LinearLayout linear = new LinearLayout(getApplicationContext()); linear.setOrientation(LinearLayout.HORIZONTAL); LayoutParams linearLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); linear.setLayoutParams(linearLayoutParams); linear.setBackgroundResource(R.color.light_orange); Button examTitle = new Button(getApplicationContext()); examTitle.setText("- " + ent2.getString("title")); examTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); examTitle.setGravity(Gravity.LEFT); examTitle.setPadding(5, 5, 0, 5); LayoutParams titleButtonLayoutParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1); examTitle.setLayoutParams(titleButtonLayoutParams); examTitle.setBackgroundColor(android.R.color.transparent); examTitle.setOnClickListener( new OnClickListener() { public void onClick(View addexam) { Intent i = new Intent(AgendaDay.this, AddExamDialog.class); i.putExtra("exam_id", ent2.getId()); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_EDIT); } }); ImageView remove = new ImageView(getApplicationContext()); LayoutParams removeButtonLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); removeButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL; remove.setBackgroundDrawable(getResources().getDrawable(R.drawable.remove)); remove.setLayoutParams(removeButtonLayoutParams); remove.setOnClickListener( new OnClickListener() { public void onClick(View removerecord) { AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this); builder .setMessage(R.string.sureExam) .setTitle(R.string.sureExamTitle) .setCancelable(true) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }) .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { ent2.delete(); fillList(); } }); AlertDialog AD = builder.create(); AD.show(); } }); linear.addView(examTitle); linear.addView(remove); examlist.addView(linear); } ImageView add = (ImageView) convertView.findViewById(R.id.add); add.setOnClickListener( new OnClickListener() { public void onClick(View addsubject) { Intent i = new Intent(AgendaDay.this, AddAssignmentListDialog.class); i.putExtra("class_id", ent.getId()); Calendar c = Calendar.getInstance(); c.set(mYear, mMonth, mDay, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); c.setTimeZone(TimeZone.getTimeZone("GMT")); i.putExtra("todayCalendar", c.getTimeInMillis()); startActivityForResult(i, ACTIVITY_CREATE); } }); } catch (Exception e) { e.printStackTrace(); } break; } return convertView; }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int margin = Utils.dpToPx(0.02f * Utils.getDisplayMetrics().widthPixels); SpannableStringBuilder prettyMessage = new SpannableStringBuilder(message); int italicsFrom = message.indexOf(italicsString), italicsTo = italicsFrom + italicsString.length(); prettyMessage.setSpan( new StyleSpan(Typeface.ITALIC), italicsFrom, italicsTo, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); this.layout = new LinearLayout(this); this.layout.setOrientation(Orientation.VERTICAL); this.setContentView(this.layout); ScrollView sv = new ScrollView(this); LayoutParams scrollParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0); scrollParams.weight = 1; // this.layout.addView(sv, scrollParams); LinearLayout innerLayout = new LinearLayout(this); innerLayout.setOrientation(Orientation.VERTICAL); LayoutParams ilParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0); ilParams.weight = 1; sv.addView(innerLayout, ilParams); this.messageText = new TextView(this); messageText.setText(prettyMessage); messageText.setTextSize(14); messageText.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); LayoutParams textParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); textParams.weight = 0; textParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL; textParams.setMargins(margin, margin, margin, margin / 2); this.layout.addView(messageText, textParams); final EditText sender = new EditText(this); sender.setInputType(InputType.TYPE_CLASS_TEXT); sender.setHint("Je e-mailadres (als je iets terug wilt horen)"); LayoutParams senderParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); senderParams.weight = 0; senderParams.setMargins(margin, 0, margin, 0); this.layout.addView(sender, senderParams); final EditText detail = new EditText(this); detail.setHint("Wat wil je zeggen?"); detail.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE); detail.setGravity(Gravity.TOP); LayoutParams detailParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0); detailParams.weight = 0.5f; detailParams.setMargins(margin, 0, margin, 0); this.layout.addView(detail, detailParams); loading = new ProgressBar(activity); loading.setIndeterminate(true); submit = new Button(this); submit.setText("Versturen"); submitParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); submitParams.weight = 0; submitParams.setMargins(0, 0, 0, margin); submitParams.gravity = Gravity.CENTER; submit.setOnClickListener( new OnClickListener() { public void onClick(View v) { activity.hideOnScreenKeyboard(sender.getWindowToken()); activity.hideOnScreenKeyboard(detail.getWindowToken()); layout.removeView(submit); layout.addView(loading, submitParams); new FeedbackSender(sender.getText().toString(), detail.getText().toString()).execute(); } }); this.layout.addView(submit, submitParams); }
@SuppressWarnings("deprecation") @Override public View getView(int position, View convertView, ViewGroup parent) { Message message1 = (Message) this.getItem(position); ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(mContext).inflate(R.layout.sms_row, parent, false); holder.message = (EmojiconTextView) convertView.findViewById(R.id.message_text); holder.thumb = (FetchableImageView) convertView.findViewById(R.id.thumb); holder.message.setPadding(10, 10, 10, 10); convertView.setTag(holder); } else holder = (ViewHolder) convertView.getTag(); if (message1.getMsgtype().equalsIgnoreCase("text")) { holder.message.setVisibility(View.VISIBLE); holder.thumb.setVisibility(View.GONE); holder.message.setText(message1.getMessage()); LayoutParams lp = (LayoutParams) holder.message.getLayoutParams(); if (message1.getIsmine().equals("yes")) { holder.message.setBackgroundResource(R.drawable.message_you); holder.message.setPadding(15, 15, 15, 15); lp.gravity = Gravity.RIGHT; lp.leftMargin = 50; lp.rightMargin = 20; } // If not mine then it is from sender to show orange background and // align to left else { holder.message.setBackgroundResource(R.drawable.message_from); holder.message.setPadding(15, 15, 15, 15); lp.gravity = Gravity.LEFT; lp.rightMargin = 50; lp.leftMargin = 20; } holder.message.setLayoutParams(lp); holder.message.setTextColor(mContext.getResources().getColor(R.color.Black)); } else { LayoutParams lp1 = (LayoutParams) holder.thumb.getLayoutParams(); holder.message.setVisibility(View.GONE); holder.thumb.setVisibility(View.VISIBLE); holder.thumb.setPadding(15, 15, 15, 15); if (message1.getMsgtype().equals("video")) { holder.thumb.setImage(message1.getMessage(), R.drawable.placeholder_video); final String url = DataManager.FILE_PATH + message1.getMessage().toString(); holder.thumb.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.parse(url), "video/*"); mContext.startActivity(intent); } }); } else if (message1.getMsgtype().equals("audio")) { holder.thumb.setImage(message1.getMessage(), R.drawable.placeholder_audio); final String url = DataManager.FILE_PATH + message1.getMessage(); holder.thumb.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Uri myUri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(myUri, "audio/*"); mContext.startActivity(intent); } }); } else if (message1.getMsgtype().equals("photo")) { holder.thumb.setImage( DataManager.FILE_PATH + message1.getMessage(), R.drawable.placeholder_image); final String url = DataManager.FILE_PATH + message1.getMessage(); holder.thumb.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.parse(url), "image/*"); mContext.startActivity(intent); } }); } if (message1.getIsmine().equals("yes")) { holder.thumb.setBackgroundResource(R.drawable.message_you); holder.thumb.setPadding(15, 15, 15, 15); lp1.gravity = Gravity.RIGHT; lp1.topMargin = 10; lp1.bottomMargin = 10; lp1.leftMargin = 50; lp1.rightMargin = 20; } // If not mine then it is from sender to show orange background and // align to left else { holder.thumb.setBackgroundResource(R.drawable.message_from); holder.thumb.setPadding(15, 15, 15, 15); lp1.gravity = Gravity.LEFT; lp1.topMargin = 10; lp1.bottomMargin = 10; lp1.rightMargin = 50; lp1.leftMargin = 20; } holder.thumb.setLayoutParams(lp1); } return convertView; }
protected void createView() { Display display = this.getWindow().getWindowManager().getDefaultDisplay(); Point size = new Point(); if (Build.VERSION.SDK_INT > 12) { display.getSize(size); } else { size.y = display.getHeight(); size.x = display.getWidth(); } int width_times = Math.round((float) size.x / (56.0f * density)); float dialog_width = ((float) (width_times - 1) * 56.0f * density); // add a view to margin the space LayoutParams mvParams = new LayoutParams((int) dialog_width, LayoutParams.WRAP_CONTENT); LinearLayout messageView = new LinearLayout(this.getContext()); messageView.setLayoutParams(mvParams); messageView.setPadding(view_padding, view_padding, view_padding, view_padding); messageView.setGravity(Gravity.TOP | Gravity.CENTER); messageView.setOrientation(LinearLayout.VERTICAL); // icon LayoutParams iconParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); iconParams.setMargins(0, 0, 0, view_margin); iconParams.gravity = Gravity.CENTER; ImageView icon = new ImageView(this.getContext()); icon.setLayoutParams(iconParams); icon.setId(android.R.id.icon); icon.setVisibility(View.GONE); // title LayoutParams titleParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); titleParams.setMargins(0, 0, 0, view_margin); TextView title = new TextView(this.getContext()); title.setLayoutParams(titleParams); title.setTextColor(this.getContext().getResources().getColor(R.color.text_color_dark)); title.setTextSize(20); title.setTypeface(null, Typeface.BOLD); title.setId(android.R.id.title); title.setVisibility(View.GONE); // message LayoutParams msgParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); TextView message = new TextView(this.getContext()); message.setLayoutParams(msgParams); message.setTextColor(this.getContext().getResources().getColor(R.color.text_color_dark)); message.setTextSize(18); message.setId(android.R.id.message); message.setVisibility(View.GONE); // optional choice LayoutParams checkBoxParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); checkBoxParams.setMargins(0, view_margin, 0, 0); CheckBox checkBox = new CheckBox(this.getContext()); checkBox.setLayoutParams(checkBoxParams); checkBox.setId(android.R.id.checkbox); checkBox.setTextColor(this.getContext().getResources().getColor(R.color.text_color_dark)); checkBox.setVisibility(View.GONE); // add elements to body view messageView.addView(icon); messageView.addView(title); messageView.addView(message); messageView.addView(checkBox); // button area LayoutParams btnsParams = new LayoutParams((int) dialog_width, (int) (52.0f * density)); LinearLayout buttons = new LinearLayout(this.getContext()); buttons.setMinimumHeight((int) (52.0f * density)); buttons.setLayoutParams(btnsParams); buttons.setGravity(Gravity.RIGHT | Gravity.CENTER); buttons.setId(android.R.id.extractArea); buttons.setPadding(0, 0, (int) (8.0f * density), 0); contentView.addView(messageView); contentView.addView(buttons); this.setContentView(contentView); }