Share Coding

Tutorials, Problems, Stuffs …

Error “Copying file obj\Debug\build.force…” and Warning “Source file ‘obj\Debug\\TemporaryGeneratedFile…” in VS2013

Error 5 Copying file obj\Debug\build.force to obj\Debug\Package\PackageTmp\obj\Debug\build.force failed. Could not find file 'obj\Debug\build.force'.
Warning	3 Source file 'obj\Debug\\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs' specified multiple times	
Warning	4 Source file 'obj\Debug\\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs' specified multiple times	
Warning	2 Source file 'obj\Debug\\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs' specified multiple times

I encountered above messages in VS2013. I tried to clean solution, rebuild project and also run VS as administrator, but those doesn’t work for me.

My solution is open xxxxxx.csproj with a notepad and delete the lines from csproj file:

<Content Include="obj\Debug\build.force" />
<Compile Include="obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs" />
<Compile Include="obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs" />
<Compile Include="obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs" />

Detect navigation bar, or get it’s height in Android

Problem: To solve different device display problem. (fitSystemWindows)

Some android device has a virtual navigation barlayout_structure_system_android1When I want the application ActionBar or content fitSystemWindows=”true”, the content shown under the Status Bar and the Navigation Bar.

It is not a solution to add padding bottom to solve this.

As the title, I try to detect if the navigation bar exist, then add padding bottom. But the detection is not reliable.

  1. Detect if has bar key
    boolean hasSoftKey = ViewConfiguration.get(context).hasPermanentMenuKey();
  2. Detect if has at least back key and home keyboolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
  3.  Get navigation bar height:The following coding get the default navigation bar height of the device. Many device have it, even they don’t have N Bar.
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
    return resources.getDimensionPixelSize(resourceId);
}
return 0;     

 

Solution: Add bottom margin when I slip the UI under the Status Bar

/* Status Bar */
protected void setStatusBar(Activity activity, int imageRes) {
    // Lower then API level 19, do nothing
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    // Do if API level >= 21 (Android 4.4)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        // This is the Android 4.4 Wear for the android watch
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // Change the background image / color of the status bar
    ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
    rootView.setFitsSystemWindows(true);
    rootView.setClipToPadding(true);

    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    if (contentView.getChildCount() > 1) {
        contentView.removeViewAt(1);
    }

    int res = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
    int height = 0;
    if (res != 0)
        height = activity.getResources().getDimensionPixelSize(res);

    ImageView image = new ImageView(activity);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
    image.setLayoutParams(params);
    image.setImageResource(imageRes);
    image.setScaleType(ImageView.ScaleType.FIT_XY);

    contentView.addView(image);
}

 

Limitation: Webview cannot set padding on it, only margin works.

App icon generator for Android and iOS

Cannot SSH while server connected VPN

Esxi 5.0 Server has a CentOS vm.
Once it connected outside VPN, it then cannot SSH because they are not the same gateway.
So we need to add route to whitelist our host IP to connect our gateway first.

Assume our gateway is 192.168.1.1, and we would like to allow all my subnetwork to pass through:

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

Entity Framework Update table without primary Key (II)

The property ‘xxx’ is part of the object’s key information and cannot be modified

UserRight dboUserRight = DBModel.UserRights.FirstOrDefault(x => x.UserID == id 
                                                             && x.PageID == pid); 
dboUserRight.CanWrite = newValue; 
DBModel.SaveChanges();

Method 1: Replace old record

UserRight updatedUserRight = new UserRight();
updatedUserRight.CanWrite = newValue;
updatedUserRight.OtherProperty = xxxx;
DBModel.UserRights.Add(updatedUserRight);
DBModel.UserRights.Remove(dboUserRight);
DBModel.SaveChanges();
Follow

Get every new post delivered to your Inbox.