Friday, 23 August 2013

Drawing image in each item of a a listView in a linear layout?

Drawing image in each item of a a listView in a linear layout?

So, I'm trying to draw a Circle on Touch for each item of a ListView.
This is my ListItem:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linkCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/linkTitle0001"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="4dp"
android:lineSpacingExtra="-2dp"
android:fontFamily="sans-serif-condensed"
android:maxLines="3"
android:text="hihi"
android:textColor="#717171"
android:textSize="49sp" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="imageOnClick"
android:src="@drawable/ic_launcher"/>
<com.example.piemenu.PieMenu
android:id="@+id/circle_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" />
</FrameLayout>
This is where I fit in the ListItem in a ListView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</ListView>
</LinearLayout>
This is my adapter:
public class ListArrayAdapter extends ArrayAdapter<String> {
public ArrayList<String> links = new ArrayList<String>();
public Activity activity = new Activity();
TextView linkText;
TextView linkDesc;
public Context c;
public ListArrayAdapter(Context context, int textViewResourceId,
ArrayList<String> fiokiList, Object o) {
super(context, textViewResourceId, fiokiList);
this.links = fiokiList;
activity = (Activity) (o);
c = context;
//notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
final String link = this.links.get(position);
linkText = (TextView) convertView.findViewById(R.id.linkTitle0001);
// linkImageView = (SmartImageView)
convertView.findViewById(R.id.faviconView0001);
linkText.setText(link);
FrameLayout fl =
(FrameLayout)convertView.findViewById(R.id.linkCardView);
ImageView imgView =
(ImageView)convertView.findViewById(R.id.imageView1);
PieMenu pieMenu = new PieMenu(imgView, activity);
fl.addView(pieMenu);
return convertView;
}
}
And this is my PieMenu class:
public class PieMenu extends FrameLayout{
// Linear
private static int ANIMATOR_DEC_SPEED15 = 1;
private static int ANIMATOR_ACC_SPEED15 = 2;
// Cascade
private static int ANIMATOR_ACC_INC_1 = ANIMATOR_ACC_SPEED15 + 1;
private static int ANIMATOR_ACC_INC_15 = ANIMATOR_ACC_INC_1 + 15;
// Special purpose
private static int ANIMATOR_BATTERY_METER = ANIMATOR_ACC_INC_15 + 1;
private static int ANIMATOR_SNAP_GROW = ANIMATOR_ACC_INC_15 + 2;
private static int ANIMATOR_END = ANIMATOR_SNAP_GROW;
private Paint mPieBackground = new Paint(COLOR_PIE_BACKGROUND);
private Paint mPieSelected = new Paint(COLOR_PIE_SELECT);
private Paint mPieOutlines = new Paint(COLOR_PIE_OUTLINES);
private Paint mSnapBackground = new Paint(COLOR_SNAP_BACKGROUND);
private static final int COLOR_OUTLINES_MASK = 0x22000000;
private static final int COLOR_ALPHA_MASK = 0xaa000000;
private static final int COLOR_OPAQUE_MASK = 0xff000000;
private static final int COLOR_SNAP_BACKGROUND = 0xffffffff;
private static final int COLOR_PIE_BACKGROUND = 0xaa000000;
private static final int COLOR_PIE_BUTTON = 0xb2ffffff;
private static final int COLOR_PIE_SELECT = 0xaaffffff;
private static final int COLOR_PIE_OUTLINES = 0x55ffffff;
private static final int COLOR_CHEVRON_LEFT = 0x0999cc;
private static final int COLOR_CHEVRON_RIGHT = 0x53d5e5;
private static final int COLOR_BATTERY_JUICE = 0x33b5e5;
private static final int COLOR_BATTERY_JUICE_LOW = 0xffbb33;
private static final int COLOR_BATTERY_JUICE_CRITICAL = 0xff4444;
private static final int COLOR_BATTERY_BACKGROUND = 0xffffff;
private static final int COLOR_STATUS = 0xffffff;
private static final int BASE_SPEED = 1000;
private static final int CHEVRON_FRAGMENTS = 16;
private static final float SIZE_BASE = 1.0f;
private ImageView _view;
private ArrayList<PieItem> mItems;
private Context _context;
private Animation animFadeOut;
public PieMenu(ImageView view, Context context) {
super(context);
_context = context;
_view = view;
setWillNotDraw(false);
mItems = new ArrayList<PieItem>();
// TODO Auto-generated constructor stub
}
public PieMenu(Context context, AttributeSet attrs) {
super(context, attrs);
// ~
}
public PieMenu(View view, Context context, AttributeSet attrs) {
super(context, attrs);
// ~
}
private CustomValueAnimator[] mAnimators = new
CustomValueAnimator[ANIMATOR_END + 1];
public void addPieMenu(int x, int y){
mItems = new ArrayList<PieItem>();
Path path = new Path();
path.addCircle(9, 9, 9, Path.Direction.CW);
PieItem item = new PieItem(_view,_context,path, x,y,40);
mItems.add(item);
//FrameLayout.LayoutParams lyp = new
FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
//pieView.setLayoutParams(lyp);
//addView(pieView);
// animateIn();
}
private class CustomValueAnimator {
@SuppressLint("NewApi")
public CustomValueAnimator(int animateIndex) {
index = animateIndex;
manual = false;
animateIn = true;
animator = ValueAnimator.ofInt(0, 1);
animator.addUpdateListener(new
CustomAnimatorUpdateListener(index));
fraction = 0;
}
@SuppressLint("NewApi")
public void start() {
if (!manual) {
animator.setDuration(duration);
animator.start();
}
}
@SuppressLint("NewApi")
public void reverse(int milliSeconds) {
if (!manual) {
animator.setDuration(milliSeconds);
animator.reverse();
}
}
@SuppressLint("NewApi")
public void cancel() {
animator.cancel();
fraction = 0;
}
public int index;
public int duration;
public boolean manual;
public boolean animateIn;
public float fraction;
public ValueAnimator animator;
}
private class CustomAnimatorUpdateListener implements
ValueAnimator.AnimatorUpdateListener {
private int mIndex;
CustomAnimatorUpdateListener(int index) {
mIndex = index;
}
@SuppressLint("NewApi")
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mAnimators[mIndex].fraction = animation.getAnimatedFraction();
invalidate();
}
}
private void animateIn() {
// Cancel & start all animations
cancelAnimation();
invalidate();
for (int i = 0; i < mAnimators.length; i++) {
//mAnimators[i].animateIn = true;
mAnimators[i].start();
}
}
private void cancelAnimation() {
for (int i = 0; i < mAnimators.length; i++) {
if (mAnimators[1] != null)
mAnimators[i].cancel();
}
}
@SuppressLint({ "NewApi", "DrawAllocation" })
@Override
protected void onDraw(Canvas canvas) {
// super.onDraw(canvas);
// Toast.makeText(_context, "text",Toast.LENGTH_LONG).show();
/*canvas.drawCircle ('1', '2', (true ?
mAnimators[ANIMATOR_SNAP_GROW].fraction *
Math.max(getWidth(), getHeight()) * 1.5f : 0),
mSnapBackground);
mSnapBackground.setAlpha((int)(10.0));
int len = (int)(10.0 * 1.3f);
int thick = (int)(len * 0.2f);
Path plus = new Path();
plus.addRect(10 - len / 2, 10 - thick / 2, 10 + len / 2, 10 +
thick / 2, Path.Direction.CW);
plus.addRect(10 - thick / 2, 10 - len / 2, 10 + thick / 2, 10 +
len / 2, Path.Direction.CW);
canvas.drawPath(plus, mSnapBackground);
canvas.save();
*/
if(mItems != null)
{
for (int i = 0; i < mItems.size();i++)
{
Paint paint1 = new Paint();
Bitmap bitmap = Bitmap.createBitmap(10, 10,
Config.ARGB_8888);
//canvas.drawBitmap(bitmap,
mItems.get(i).x+1,mItems.get(i).y+8, paint1);
Bitmap bgr =
BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
Paint transparentpainthack = new Paint();
transparentpainthack.setAlpha(100);
// canvas.drawBitmap(bgr, mItems.get(i).x,
mItems.get(i).y, transparentpainthack);
ValueAnimator animator;
animator = ValueAnimator.ofFloat(0, 1); // values
from 0 to 1
animator.setDuration(5000); // 5 seconds duration
from 0 to 1
paint1.setColor(Color.RED);
paint1.setAntiAlias(true);
paint1.setFilterBitmap(true);
paint1.setDither(true);
paint1.setStyle(Paint.Style.STROKE);
//Bitmap myBitmap =
BitmapFactory.decodeResource(getResources(),
BitmapDrawable drawable = (BitmapDrawable)
_view.getDrawable();
Bitmap bitmap1 = drawable.getBitmap();
canvas.drawBitmap(bitmap1, mItems.get(i).x,
mItems.get(i).y, transparentpainthack);
canvas.drawCircle(mItems.get(i).x, mItems.get(i).y,
mItems.get(i).r + 50, paint1);
animator.addUpdateListener(new
ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator
animation) {
float value = ((Float)
(animation.getAnimatedValue()))
.floatValue();
// Set translation of your view here.
Position can be calculated
// out of value. This code should move the
view in a half circle.
_view.setTranslationX((float)(200.0 *
Math.sin(value*Math.PI)));
_view.setTranslationY((float)(200.0 *
Math.cos(value*Math.PI)));
}
});
}
}
// this.draw(canvas);
//_view.draw(canvas);
//for (PieItem item : mItems) {
// //if (!canItemDisplay(item)) continue;
//drawItem(canvas, item);
//\] }
}
/*
@SuppressLint("NewApi")
private void drawItem(Canvas canvas, PieItem item) {
if (item.getView() != null) {
int state = canvas.save();
float angle = (float) Math.abs(Math.acos(10)) * 2.0f;
canvas.rotate(angle + 20, 10, 10);
canvas.drawPath(item.getPath(), item.isSelected() ?
mPieSelected : mPieBackground);
canvas.drawPath(item.getPath(), mPieOutlines);
canvas.restoreToCount(state);
state = canvas.save();
ImageView view = (ImageView)item.getView();
canvas.translate(view.getX(), view.getY());
// canvas.rotate(angle,(float)10,view.getWidth() / 2,
view.getHeight() / 2);
view.draw(canvas);
canvas.restoreToCount(state);
}
}
*/
@Override
public boolean onTouchEvent(MotionEvent evt) {
if (evt.getPointerCount() > 1) return true;
final float touchX = evt.getRawX();
final float touchY = evt.getRawY();
BitmapDrawable drawable = (BitmapDrawable) _view.getDrawable();
Bitmap bitmap1 = drawable.getBitmap();
Log.d("height",String.valueOf(bitmap1.getWidth()));
if(mItems.isEmpty()){
Path path = new Path();
path.addCircle(9, 9, 9, Path.Direction.CW);
PieItem item = new PieItem(_view,_context,path,
touchX,touchY,40);
mItems.add(item);
}
switch (evt.getAction()) {
case MotionEvent.ACTION_DOWN:
//if (mItems == null){
//}
for(int i = 0;i<mItems.size();i++){
// Toast.makeText(_context,
"tas",Toast.LENGTH_SHORT).show();
if (touchX >= mItems.get(i).x &&
touchX <= (mItems.get(i).x + bitmap1.getWidth()) &&
touchY >= mItems.get(i).y &&
touchY <= (mItems.get(i).y + bitmap1.getHeight())) {
// click code
Toast.makeText(_context, "asa",
Toast.LENGTH_SHORT).show();
}
}
break;
}
//Toast.makeText(_context, String.valueOf(mX),
Toast.LENGTH_LONG).show();
invalidate();
return true;
}
}
I'm just finding it a bit difficult to understand how to draw a
cirle/piemenu for onTouch of each item of a listview.

EditText not scrollable inside the Listview?

EditText not scrollable inside the Listview?

I have ListView which is also scrollable and inside it there is MultiLine
EditText which is not scrollable properly when I wanted to scroll the
EdiText then Listview's scroll works while I wanted to scroll the Editext.
so please suggest some good ways to handle this.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/et_address"
style="@style/Text.Medium"
android:layout_width="0dp"
andr`enter code here`oid:layout_height="wrap_content"
android:layout_weight="9"
android:gravity="top"
android:hint="@string/address"
android:inputType="textMultiLine|textCapSentences"
android:maxHeight="75dp"
android:maxLength="256"
android:minLines="2"
android:scrollbars="vertical"
/>
</LinearLayout>

Move div background position on jquery hover

Move div background position on jquery hover

I'm trying to get this to work but for some unknown reason the image isn't
budging.. Check out the JSfiddle I created here.
//Ignore this comment

Thursday, 22 August 2013

Windows 2008 Server GPO Add personal shares

Windows 2008 Server GPO Add personal shares

Right now each employee has their own share on the file server that uses
their first initial of their first name and their last name (ex. jsmith).
Of course John Simth has to be logged on to access the share jsmith.
The Issue: Right now I have two options to establish the jsmith share
everytime a employee logins into the domain creating a domain profile for
the 1st time. I ether 1.) manually map the drive to the share. Or 2.) use
the VBScript below and manually open it or manually put it in the startup
folder.
The Goal: I woud like to use a GPO login script or the GPO map drive
function to make sure the employee has their personal share (mapped to
W:). Right now the only solution I can figure out is to add the VBScript
below as a Login script(using GPO), BUT it will not run like it should.
There is NOTHING wrong with the script if I manually put it on the users
computer and click it. But how would I make sure the users personal share
is being mapped everytime the login to the domain on ANY computer? NOTE: I
do not need to use the login script below, but its the only option I
currently know of.
VBScript:
' Section removes W drive if exists
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
If (objFSO.DriveExists("W:") = True) Then
objNetwork.RemoveNetworkDrive "W:", True, True
End If
' Section Remaps W drive based on User Name, the OU is also stored but not
used.
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strUserName = objUser.samAccountName
strOUPath = objUser.Parent
arrContainers = Split(strOUPath, ",")
arrOU = Split(arrContainers(0), "=")
strOU = arrOU(1)
strDrive = "\\SERVER001\" & strUserName
strFirstInt= Left(strUserName,1)
strLastName= Split(strUserName, " ")(1)
strDrive = "\\192.168.0.1\" & strFirstInt & strLastName
'WScript.Echo (strDrive)
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.MapNetworkDrive "W:", strDrive

n+1 vectors in $\mathbb{R}^n$ cannot be linearly independent

n+1 vectors in $\mathbb{R}^n$ cannot be linearly independent

I was looking for a short snazzy proof on the following statement:
n+1 vectors in $\mathbb{R}^n$ cannot be linearly independent
A student of mine asked this today morning and I couldn't come up with a
proof solely from the definition of linear independence.
From a higher level perspective, I explained that if I put the vectors in
a matrix then if the only null space entry is the zero vector, then the
vectors are independent but since we have one extra column than row and
that the row and column rank are equal, there is no way we can have $n+1$
as the rank of the matrix and hence from Rank-Nullity theorem, the
dimension of the Nullspace is at least one which implies that there is a
combination of the vectors where not all the scalar multiples in the
definition are 0 but yet we get a zero as the linear combination. The
student hasn't completely learnt the fundamental subspaces yet so I am not
sure he grasped what I was saying.
Is there a cleaner proof?
EDIT: I am stunned how many beautiful answers I got with so much diversity.

Do chatrooms help when stuck on programming obstacles?

Do chatrooms help when stuck on programming obstacles?

I'm curious, sometimes when I'm working on a project, I am lost about
where to begin and so I can't exactly ask something on StackOverflow
because I'm not at a specific problem. But I'd like to perhaps chat with
people. Are chatrooms good ways to do so? i heard of IRC rooms, how do you
utilize these to advantage?

Center aligned paragraph on top of left aligned paragraph

Center aligned paragraph on top of left aligned paragraph

Suppose I have:
<p align="center">Title</p>
<p>Body</p>
How can I make it so there is no line space between "Title" and "Body" ?